Configure Cucumber with SentientUser

Posted by Corith Malin on Stack Overflow See other posts from Stack Overflow or by Corith Malin
Published on 2010-03-29T04:00:22Z Indexed on 2010/03/29 4:03 UTC
Read the original article Hit count: 607

Filed under:
|
|
|

I have an application using the SentientUser gem to provide the current user to my models. On top of that I'm using default scoping to ensure that a user can only ever access data that they own. So a typical model for me looks something like this:

class Location < ActiveRecord::Base
  validates_presence_of :name, :time_zone, :address

  belongs_to :account
  belongs_to :address

  accepts_nested_attributes_for :address

  default_scope :conditions => { :account_id => User.current.account }
end

When I run rake cucumber I get an error on the default_scope line about account being nil. My guess is that when the cucumber rake task is run it doesn't have access to the correct application controller to inject the current_user method and thus SentientUser can't get the current user? The error I get is:

rake cucumber
(in /Users/corithmalin/Documents/Code/Ruby/flavorpulse)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I "/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/lib:lib" "/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/cucumber"  --profile default
Using the default profile...
undefined method `account' for nil:NilClass (NoMethodError)
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/vendor/rails/activesupport/lib/active_support/whiny_nil.rb:52:in `method_missing'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/app/models/location.rb:9
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require'
/Library/Ruby/Gems/1.8/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in `require'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/vendor/rails/activesupport/lib/active_support/dependencies.rb:265:in `require_or_load'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/vendor/rails/activesupport/lib/active_support/dependencies.rb:224:in `depend_on'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/vendor/rails/activesupport/lib/active_support/dependencies.rb:136:in `require_dependency'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:414:in `load_application_classes'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:413:in `each'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:413:in `load_application_classes'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:411:in `each'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:411:in `load_application_classes'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:197:in `process'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/config/environment.rb:9
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require'
/Library/Ruby/Gems/1.8/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/Users/corithmalin/Documents/Code/Ruby/flavorpulse/features/support/env.rb:8
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require'
/Library/Ruby/Gems/1.8/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/rb_support/rb_language.rb:124:in `load_code_file'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/step_mother.rb:85:in `load_code_file'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/step_mother.rb:77:in `load_code_files'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/step_mother.rb:76:in `each'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/step_mother.rb:76:in `load_code_files'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/cli/main.rb:48:in `execute!'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/Library/Ruby/Gems/1.8/gems/cucumber-0.6.3/bin/cucumber:8
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]

(See full trace by running task with --trace)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby