Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyoho committed Mar 6, 2012
1 parent 8ebfc7b commit 994fd9b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 3 deletions.
85 changes: 85 additions & 0 deletions features/nested_resources_scope_properly.feature
@@ -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
"""
16 changes: 13 additions & 3 deletions templates/generate_custom.rb
@@ -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.