Skip to content

Instantly share code, notes, and snippets.

@wdiechmann
Created February 6, 2012 02:02
Show Gist options
  • Save wdiechmann/1748930 to your computer and use it in GitHub Desktop.
Save wdiechmann/1748930 to your computer and use it in GitHub Desktop.
Shoulda and Rspec question on undefined method 'have'
ruby-1.9.2-p290 :013 > @ox = Factory.create(:ox, id: 1)
=> #<Ox id: 1, name: "oxen", siteurl: "www.oxen.dk", created_at: "2012-02-06 01:46:15", updated_at: "2012-02-06 01:46:15", active: nil>
ruby-1.9.2-p290 :014 > user = Factory.create(:user, ox: @ox)
=> #<User id: 253, email: "[email protected]", encrypted_password: "$2a$04$LgSZM2RH6Q5rW5WSpH8vmeKL/AXtHQ5WViUPfPZQcqaz...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, password_salt: nil, confirmation_token: "erGxuzj8Mtk3jY63xNdK", confirmed_at: nil, confirmation_sent_at: "2012-02-06 01:46:30", unconfirmed_email: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, created_at: "2012-02-06 01:46:30", updated_at: "2012-02-06 01:46:30", username: "username", ox_id: 1, approved: false, active: nil>
ruby-1.9.2-p290 :015 > role = Factory.create(:role, ox: @ox)
=> #<Role id: 218, ox_id: 1, name: "Role_2", created_at: "2012-02-06 01:46:39", updated_at: "2012-02-06 01:46:39", active: nil>
ruby-1.9.2-p290 :016 > permission = Factory.create( :roleable, authorization: "all", ox: @ox, role: role )
=> #<Roleable id: 370, ox_id: 1, role_id: 218, roleable_id: nil, roleable_type: nil, authorization: "all", controller: nil, created_at: "2012-02-06 01:47:14", updated_at: "2012-02-06 01:47:14">
ruby-1.9.2-p290 :017 > user_group = Factory.create(:user_group, ox: @ox, name: "UG1")
=> #<UserGroup id: 421, ox_id: 1, name: "UG1", created_at: "2012-02-06 01:51:49", updated_at: "2012-02-06 01:51:49", active: nil>
ruby-1.9.2-p290 :018 > user_group.roleables << permission
=> [#<Roleable id: 370, ox_id: 1, role_id: 218, roleable_id: 421, roleable_type: "UserGroup", authorization: "all", controller: nil, created_at: "2012-02-06 01:47:14", updated_at: "2012-02-06 01:52:01">]
ruby-1.9.2-p290 :019 > user.user_groups << user_group
=> [#<UserGroup id: 421, ox_id: 1, name: "UG1", created_at: "2012-02-06 01:51:49", updated_at: "2012-02-06 01:51:49", active: nil>]
ruby-1.9.2-p290 :024 > user.user_groups[0].roles
=> [#<Role id: 218, ox_id: 1, name: "Role_2", created_at: "2012-02-06 01:46:39", updated_at: "2012-02-06 01:46:39", active: nil>]
ruby-1.9.2-p290 :025 > user.user_groups[0].should have(1).roles
NoMethodError: undefined method `have' for main:Object
from (irb):25
from /Users/walther/.rvm/gems/ruby-1.9.2-p290@oxenserver/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
from /Users/walther/.rvm/gems/ruby-1.9.2-p290@oxenserver/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
from /Users/walther/.rvm/gems/ruby-1.9.2-p290@oxenserver/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ruby-1.9.2-p290 :026 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment