Rails Arel unit test error

49 views
Skip to first unread message

Bazley

unread,
Dec 28, 2014, 5:08:35 AM12/28/14
to rubyonra...@googlegroups.com

I have the following error:

ERROR["test_character_should_be_valid", CharacterTest, 0.214787]
test_character_should_be_valid#CharacterTest (0.21s)
NoMethodError:         NoMethodError: undefined method `val' for "$1":Arel::Nodes::BindParam
app/models/user.rb:11:in `block in <class:User>'
test/models/character_test.rb:8:in `setup'

From the following test: test/models/character_test.rb:

    require 'test_helper'

    class CharacterTest < ActiveSupport::TestCase

      def setup
        @user = User.new(name: "Example User", email: "us...@example.com", callsign: "example",
                         password: "foobar", password_confirmation: "foobar")
        @user.save
        @character = @user.character
      end

      test "character should be valid" do
        assert @character.valid?
      end

    end # CharacterTest

In the gemfile:

gem 'arel', '6.0.0.beta2'

character.rb:

class Character < ActiveRecord::Base
  belongs_to :sociable, polymorphic: true
end

user.rb:

class User < ActiveRecord::Base

  has_one  :character, as: :sociable

  before_validation do
    self.create_character unless character
  end
  .
  .
end

I can't find anything about this particular arel error. My arel gem is 6.0.0.beta2, which seems to fix other problems (as in here). Has anyone seen anything like this before?

Colin Law

unread,
Dec 28, 2014, 5:35:15 AM12/28/14
to rubyonra...@googlegroups.com
You have not told us which is line 11 in user.rb, which is the line it
says the error is on.

Colin

Bazley

unread,
Dec 28, 2014, 5:42:00 AM12/28/14
to rubyonra...@googlegroups.com
Sorry, line 11 is:
self.create_character unless character # line 11


Jem P.

unread,
Dec 31, 2014, 9:53:22 AM12/31/14
to rubyonra...@googlegroups.com
Problem solved: it's because the columns sociable_id and sociable_type
weren't defined in the schema.

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages