LoginSignup
4
4

More than 5 years have passed since last update.

Rails つまづき駆動投稿(TDP)

Posted at

Rails つまづき駆動投稿

Tsumaduki Driven Post
略してTDP

はい、すみません。
言ってみたかっただけです。

PHPer からRailsを利用するにあたって、
躓いたポイントをまとめて、
一次対応、恒久対応などを記録して
自分の備忘録としようと思います。

トピックとしてまとまったら切り出します。

環境

Mac
ruby 2.3.3
Bundler version 1.14.6
Rails 5.0.1
Heroku

ActionMailerのテストでエラー

Rails Tutorialを参考にしたテストコードの一部で
以下のような assert_match を使うと

test/mailers/user_mailer_test.rb
  test "account_activation" do
    user = users(:michael)
    user.activation_token = User.new_token
    mail = UserMailer.account_activation(user)
    assert_match user.first_name,               mail.body.encoded

下記のようなエラーが出力される

 FAIL["test_account_activation", UserMailerTest, 0.9477509999996983]
 test_account_activation#UserMailerTest (0.95s)
        Expected /Michael/ to match # encoding: US-ASCII
        "\r\n----==_mimepart_58cfdb6148a_7df93fe0b803fa247557\r\nContent-Type: text/plain;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n\r\nRXhhbXBsZU1pY2hhZWzmp5gKCiAgUGxheWluc3RhbGzjgavjgZTnmbvpjLLj\r\ngYTjgZ/jgaDjgY3jgIHjgYLjgorjgYzjgajjgYbjgZTjgZbjgYTjgb7jgZnj\r\ngIIKI 

一次対応
http://easyramble.com/test-action-mailer-with-rspec.html
こちらの記事を参考に、Base64 encodeをデコードして比較するように変更

test/mailers/user_mailer_test.rb
assert_match user.first_name,               mail.body.encoded.split(/\r\n/).map{|i| Base64.decode64(i)}.join

解決。 意味をちゃんと理解しよう。

Rails server is already running のとき

rails s 
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
A server is already running. Check /Users/ココにパスがはいる/tmp/pids/server.pid.

pid削除するとPC再起動が必要だったので
記事を検索
http://qiita.com/blueinkinc/items/f5114cfb9ba3b0631bc0
などでは

ps ax | grep rails 

とあるが、プロセスに出てこなかったため
pumaを消した

 ps ax | grep puma 
37914 s006  S+     0:05.14 puma 3.4.0 (tcp://localhost:3000) [アプリ名]
38219 s006  S+     0:08.14 puma: cluster worker 0: 37914 [アプリ名]
38275 s006  S+     0:08.59 puma: cluster worker 1: 37914 [アプリ名]
kill -9 37914

基本的に親プロセスをKillすると子も終了しますが、
同じコマンド叩いてまだいるようなら子も消してください。

\w $ rails s
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[39809] Puma starting in cluster mode...
[39809] * Version 3.4.0 (ruby 2.3.3-p222), codename: Owl Bowl Brawl
[39809] * Min threads: 5, max threads: 5
[39809] * Environment: development

無事起動したのでめでたしめでたし。

Herokuの bundler のバージョンが上がらない

HerokuのrubyのバージョンはGemfile

Gemfile
ruby '2.3.3'

などと指定しておくと、herokuへのデプロイ時に
rbenvでバージョンを変更してくれるようですが、
bundlerのバージョンに関しては、
基本的に指定できないようです。
参考

herokuでどのバージョンが使われるかはこちら
に記載されているようなので、これよりローカルのバージョンを上げないように
したほうが良いかと思われます。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4