Permalink
Browse files

wip

  • Loading branch information...
1 parent 8ebfc7b commit 994fd9b70eafc02301fc1e4183f64ba42d0bf279 @mattyoho committed Mar 6, 2012
Showing with 98 additions and 3 deletions.
  1. +85 −0 features/nested_resources_scope_properly.feature
  2. +13 −3 templates/generate_custom.rb
@@ -0,0 +1,85 @@
+Feature: Nested Resources Scope Properly
+
+ Background:
+ Given a file named "app/controllers/sprockets_controller.rb" with:
+ """
+ class SprocketsController < AuthenticatingController
+ default_assumption :rails
+ assume :sprocket, :raise_error => true
+
+ rescue_from ActiveRecord::RecordNotFound do
+ render :text => "Not Found", :status => 404
+ end
+ end
+ """
+ And a file named "app/views/widgets/show.html.erb" with:
+ """
+ <span><%= widget.name %></span> dances with <span><%= sprocket.name %></span>
+ """
+
+ Scenario: Scoping with a symbol success
+ Given a file named "features/widget_is_viewed_by_owner.feature" with:
+ """
+ Feature: Find A Record Owned By You
+ Scenario: success
+ Given I own a sprocket named "Fred" owned by a widget named "Ginger"
+ When I view the widget's sprocket
+ Then I should see "Ginger dances with Fred"
+ """
+ When I run `cucumber features/widget_is_viewed_by_owner.feature` with a clean Bundler environment
+ Then the output should contain:
+ """
+ 1 scenario (1 passed)
+ 3 steps
+ """
+
+ Scenario: Scoping with a symbol failure
+ Given a file named "features/widget_is_viewed_by_owner.feature" with:
+ """
+ Feature: Don't Find Record Not Belonging To You
+ Scenario: success
+ Given a widget named "spacely"
+ When I view the widget
+ Then I should see "Not Found"
+ """
+ When I run `cucumber features/widget_is_viewed_by_owner.feature` with a clean Bundler environment
+ Then the output should contain:
+ """
+ 1 scenario (1 passed)
+ 3 steps
+ """
+
+ Scenario: Scoping with a hash success
+ Given a file named "app/controllers/widgets_controller.rb" with:
+ """
+ class Owner
+ attr_accessor :id
+ end
+
+ class WidgetsController < AuthenticatingController
+ default_assumption :rails
+ assume :widget, :owner => {:object => :current_owner, :column_name => :user_id}
+
+ def current_owner
+ Owner.new.tap {|u| u.id = 42}
+ end
+
+ rescue_from ActiveRecord::RecordNotFound do
+ render :text => "Not Found", :status => 404
+ end
+ end
+ """
+ And a file named "features/widget_is_viewed_by_owner.feature" with:
+ """
+ Feature: Find A Record Owned By You
+ Scenario: success
+ Given I own a widget named "sprocket"
+ When I view the widget
+ Then I should see "sprocket"
+ """
+ When I run `cucumber features/widget_is_viewed_by_owner.feature` with a clean Bundler environment
+ Then the output should contain:
+ """
+ 1 scenario (1 passed)
+ 3 steps
+ """
@@ -1,6 +1,16 @@
generate('resource widget name:string user_id:integer')
generate('resource derived_widget')
+generate('resource sprocket name:string widget_id:integer')
-run('rake db:reset')
-run('rake db:migrate')
-run('rake db:test:prepare')
+inside('app/models') do
+ inject_into_class('widget.rb', 'Widget') do
+ " has_many :sprockets\n"
+ end
+ inject_into_class('sprocket.rb', 'Sprocket') do
+ " belongs_to :widget\n"
+ end
+end
+
+rake('db:reset')
+rake('db:migrate')
+rake('db:test:prepare')

0 comments on commit 994fd9b

Please sign in to comment.