Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed should_be_restful

  • Loading branch information...
commit 33f547cf81466896a4dbc1844b34b76221f1ea7d 1 parent a37d4c5
Joe Ferris jferris authored
4 lib/shoulda/controller.rb
... ... @@ -1,7 +1,6 @@
1 1 require 'shoulda'
2 2 require 'shoulda/controller/helpers'
3 3 require 'shoulda/controller/matchers'
4   -require 'shoulda/controller/resource_options'
5 4 require 'shoulda/controller/macros'
6 5
7 6 module Test # :nodoc: all
@@ -10,9 +9,6 @@ class TestCase
10 9 include Shoulda::Controller::Matchers
11 10 include Shoulda::Controller::Helpers
12 11 extend Shoulda::Controller::Macros
13   - Shoulda::Controller::VALID_FORMATS.each do |format|
14   - include "Shoulda::Controller::#{format.to_s.upcase}".constantize
15   - end
16 12 end
17 13 end
18 14 end
199 lib/shoulda/controller/formats/html.rb
... ... @@ -1,199 +0,0 @@
1   -module Shoulda # :nodoc:
2   - module Controller # :nodoc:
3   - module HTML # :nodoc: all
4   - def self.included(other)
5   - other.class_eval do
6   - extend Shoulda::Controller::HTML::ClassMethods
7   - end
8   - end
9   -
10   - module ClassMethods
11   - def controller_name_from_class
12   - self.name.gsub(/Test/, '')
13   - end
14   -
15   - def make_show_html_tests(res)
16   - context "on GET to #{controller_name_from_class}#show" do
17   - setup do
18   - record = get_existing_record(res)
19   - parent_params = make_parent_params(res, record)
20   - get :show, parent_params.merge({ res.identifier => record.to_param })
21   - end
22   -
23   - if res.denied.actions.include?(:show)
24   - should_not_assign_to res.object
25   - should_redirect_to res.denied.redirect
26   - should_set_the_flash_to res.denied.flash
27   - else
28   - should_assign_to res.object
29   - should_respond_with :success
30   - should_render_template :show
31   - should_not_set_the_flash
32   - end
33   - end
34   - end
35   -
36   - def make_edit_html_tests(res)
37   - context "on GET to #{controller_name_from_class}#edit" do
38   - setup do
39   - @record = get_existing_record(res)
40   - parent_params = make_parent_params(res, @record)
41   - get :edit, parent_params.merge({ res.identifier => @record.to_param })
42   - end
43   -
44   - if res.denied.actions.include?(:edit)
45   - should_not_assign_to res.object
46   - should_redirect_to res.denied.redirect
47   - should_set_the_flash_to res.denied.flash
48   - else
49   - should_assign_to res.object
50   - should_respond_with :success
51   - should_render_template :edit
52   - should_not_set_the_flash
53   - should_render_a_form
54   - should "set @#{res.object} to requested instance" do
55   - assert_equal @record, assigns(res.object)
56   - end
57   - end
58   - end
59   - end
60   -
61   - def make_index_html_tests(res)
62   - context "on GET to #{controller_name_from_class}#index" do
63   - setup do
64   - record = get_existing_record(res) rescue nil
65   - parent_params = make_parent_params(res, record)
66   - get(:index, parent_params)
67   - end
68   -
69   - if res.denied.actions.include?(:index)
70   - should_not_assign_to res.object.to_s.pluralize
71   - should_redirect_to res.denied.redirect
72   - should_set_the_flash_to res.denied.flash
73   - else
74   - should_respond_with :success
75   - should_assign_to res.object.to_s.pluralize
76   - should_render_template :index
77   - should_not_set_the_flash
78   - end
79   - end
80   - end
81   -
82   - def make_new_html_tests(res)
83   - context "on GET to #{controller_name_from_class}#new" do
84   - setup do
85   - record = get_existing_record(res) rescue nil
86   - parent_params = make_parent_params(res, record)
87   - get(:new, parent_params)
88   - end
89   -
90   - if res.denied.actions.include?(:new)
91   - should_not_assign_to res.object
92   - should_redirect_to res.denied.redirect
93   - should_set_the_flash_to res.denied.flash
94   - else
95   - should_respond_with :success
96   - should_assign_to res.object
97   - should_not_set_the_flash
98   - should_render_template :new
99   - should_render_a_form
100   - end
101   - end
102   - end
103   -
104   - def make_destroy_html_tests(res)
105   - context "on DELETE to #{controller_name_from_class}#destroy" do
106   - setup do
107   - @record = get_existing_record(res)
108   - parent_params = make_parent_params(res, @record)
109   - delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
110   - end
111   -
112   - if res.denied.actions.include?(:destroy)
113   - should_redirect_to res.denied.redirect
114   - should_set_the_flash_to res.denied.flash
115   -
116   - should "not destroy record" do
117   - assert_nothing_raised { assert @record.reload }
118   - end
119   - else
120   - should_set_the_flash_to res.destroy.flash
121   - if res.destroy.redirect.is_a? Symbol
122   - should_respond_with res.destroy.redirect
123   - else
124   - should_redirect_to res.destroy.redirect
125   - end
126   -
127   - should "destroy record" do
128   - assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
129   - @record.reload
130   - end
131   - end
132   - end
133   - end
134   - end
135   -
136   - def make_create_html_tests(res)
137   - context "on POST to #{controller_name_from_class}#create with #{res.create.params.inspect}" do
138   - setup do
139   - record = get_existing_record(res) rescue nil
140   - parent_params = make_parent_params(res, record)
141   - @count = res.klass.count
142   - post :create, parent_params.merge(res.object => res.create.params)
143   - end
144   -
145   - if res.denied.actions.include?(:create)
146   - should_redirect_to res.denied.redirect
147   - should_set_the_flash_to res.denied.flash
148   - should_not_assign_to res.object
149   -
150   - should "not create new record" do
151   - assert_equal @count, res.klass.count
152   - end
153   - else
154   - should_assign_to res.object
155   - should_set_the_flash_to res.create.flash
156   - if res.create.redirect.is_a? Symbol
157   - should_respond_with res.create.redirect
158   - else
159   - should_redirect_to res.create.redirect
160   - end
161   -
162   - should "not have errors on @#{res.object}" do
163   - assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
164   - end
165   - end
166   - end
167   - end
168   -
169   - def make_update_html_tests(res)
170   - context "on PUT to #{controller_name_from_class}#update with #{res.create.params.inspect}" do
171   - setup do
172   - @record = get_existing_record(res)
173   - parent_params = make_parent_params(res, @record)
174   - put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
175   - end
176   -
177   - if res.denied.actions.include?(:update)
178   - should_not_assign_to res.object
179   - should_redirect_to res.denied.redirect
180   - should_set_the_flash_to res.denied.flash
181   - else
182   - should_assign_to res.object
183   - should_set_the_flash_to(res.update.flash)
184   - if res.update.redirect.is_a? Symbol
185   - should_respond_with res.update.redirect
186   - else
187   - should_redirect_to res.update.redirect
188   - end
189   -
190   - should "not have errors on @#{res.object}" do
191   - assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
192   - end
193   - end
194   - end
195   - end
196   - end
197   - end
198   - end
199   -end
168 lib/shoulda/controller/formats/xml.rb
... ... @@ -1,168 +0,0 @@
1   -module Shoulda # :nodoc:
2   - module Controller # :nodoc:
3   - module XML
4   - def self.included(other) #:nodoc:
5   - other.class_eval do
6   - extend Shoulda::Controller::XML::ClassMethods
7   - end
8   - end
9   -
10   - module ClassMethods
11   - # Macro that creates a test asserting that the controller responded with an XML content-type
12   - # and that the XML contains +<name/>+ as the root element.
13   - def should_respond_with_xml_for(name = nil)
14   - should "have ContentType set to 'application/xml'" do
15   - assert_xml_response
16   - end
17   -
18   - if name
19   - should "return <#{name}/> as the root element" do
20   - body = @response.body.first(100).map {|l| " #{l}"}
21   - assert_select name.to_s.dasherize, 1, "Body:\n#{body}...\nDoes not have <#{name}/> as the root element."
22   - end
23   - end
24   - end
25   - alias should_respond_with_xml should_respond_with_xml_for
26   -
27   - protected
28   -
29   - def make_show_xml_tests(res) # :nodoc:
30   - context "on GET to #{controller_name_from_class}#show as xml" do
31   - setup do
32   - request_xml
33   - record = get_existing_record(res)
34   - parent_params = make_parent_params(res, record)
35   - get :show, parent_params.merge({ res.identifier => record.to_param })
36   - end
37   -
38   - if res.denied.actions.include?(:show)
39   - should_not_assign_to res.object
40   - should_respond_with 401
41   - else
42   - should_assign_to res.object
43   - should_respond_with :success
44   - should_respond_with_xml_for res.object
45   - end
46   - end
47   - end
48   -
49   - def make_edit_xml_tests(res) # :nodoc:
50   - # XML doesn't need an :edit action
51   - end
52   -
53   - def make_new_xml_tests(res) # :nodoc:
54   - # XML doesn't need a :new action
55   - end
56   -
57   - def make_index_xml_tests(res) # :nodoc:
58   - context "on GET to #{controller_name_from_class}#index as xml" do
59   - setup do
60   - request_xml
61   - parent_params = make_parent_params(res)
62   - get(:index, parent_params)
63   - end
64   -
65   - if res.denied.actions.include?(:index)
66   - should_not_assign_to res.object.to_s.pluralize
67   - should_respond_with 401
68   - else
69   - should_respond_with :success
70   - should_respond_with_xml_for res.object.to_s.pluralize
71   - should_assign_to res.object.to_s.pluralize
72   - end
73   - end
74   - end
75   -
76   - def make_destroy_xml_tests(res) # :nodoc:
77   - context "on DELETE to #{controller_name_from_class}#destroy as xml" do
78   - setup do
79   - request_xml
80   - @record = get_existing_record(res)
81   - parent_params = make_parent_params(res, @record)
82   - delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
83   - end
84   -
85   - if res.denied.actions.include?(:destroy)
86   - should_respond_with 401
87   -
88   - should "not destroy record" do
89   - assert @record.reload
90   - end
91   - else
92   - should "destroy record" do
93   - assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
94   - @record.reload
95   - end
96   - end
97   - end
98   - end
99   - end
100   -
101   - def make_create_xml_tests(res) # :nodoc:
102   - context "on POST to #{controller_name_from_class}#create as xml" do
103   - setup do
104   - request_xml
105   - parent_params = make_parent_params(res)
106   - @count = res.klass.count
107   - post :create, parent_params.merge(res.object => res.create.params)
108   - end
109   -
110   - if res.denied.actions.include?(:create)
111   - should_respond_with 401
112   - should_not_assign_to res.object
113   -
114   - should "not create new record" do
115   - assert_equal @count, res.klass.count
116   - end
117   - else
118   - should_assign_to res.object
119   -
120   - should "not have errors on @#{res.object}" do
121   - assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
122   - end
123   - end
124   - end
125   - end
126   -
127   - def make_update_xml_tests(res) # :nodoc:
128   - context "on PUT to #{controller_name_from_class}#update as xml" do
129   - setup do
130   - request_xml
131   - @record = get_existing_record(res)
132   - parent_params = make_parent_params(res, @record)
133   - put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
134   - end
135   -
136   - if res.denied.actions.include?(:update)
137   - should_not_assign_to res.object
138   - should_respond_with 401
139   - else
140   - should_assign_to res.object
141   -
142   - should "not have errors on @#{res.object}" do
143   - assert_equal [], assigns(res.object).errors.full_messages, "@#{res.object} has errors:"
144   - end
145   - end
146   - end
147   - end
148   - end
149   -
150   - # Sets the next request's format to 'application/xml'
151   - def request_xml
152   - @request.accept = "application/xml"
153   - end
154   -
155   - # Asserts that the controller's response was 'application/xml'
156   - def assert_xml_response
157   - content_type = (@response.headers["Content-Type"] || @response.headers["type"]).to_s
158   - regex = %r{\bapplication/xml\b}
159   -
160   - msg = "Content Type '#{content_type.inspect}' doesn't match '#{regex.inspect}'\n"
161   - msg += "Body: #{@response.body.first(100).chomp} ..."
162   -
163   - assert_match regex, content_type, msg
164   - end
165   -
166   - end
167   - end
168   -end
51 lib/shoulda/controller/macros.rb
@@ -21,60 +21,9 @@ module Controller # :nodoc:
21 21 # end
22 22 #
23 23 # Would produce 5 tests for the +show+ action
24   - #
25   - # Furthermore, the should_be_restful helper will create an entire set of tests which will verify that your
26   - # controller responds restfully to a variety of requested formats.
27 24 module Macros
28 25 include Matchers
29 26
30   - # <b>DEPRECATED:</b> Please see
31   - # http://thoughtbot.lighthouseapp.com/projects/5807/tickets/78 for more
32   - # information.
33   - #
34   - # Generates a full suite of tests for a restful controller.
35   - #
36   - # The following definition will generate tests for the +index+, +show+, +new+,
37   - # +edit+, +create+, +update+ and +destroy+ actions, in both +html+ and +xml+ formats:
38   - #
39   - # should_be_restful do |resource|
40   - # resource.parent = :user
41   - #
42   - # resource.create.params = { :title => "first post", :body => 'blah blah blah'}
43   - # resource.update.params = { :title => "changed" }
44   - # end
45   - #
46   - # This generates about 40 tests, all of the format:
47   - # "on GET to :show should assign @user."
48   - # "on GET to :show should not set the flash."
49   - # "on GET to :show should render 'show' template."
50   - # "on GET to :show should respond with success."
51   - # "on GET to :show as xml should assign @user."
52   - # "on GET to :show as xml should have ContentType set to 'application/xml'."
53   - # "on GET to :show as xml should respond with success."
54   - # "on GET to :show as xml should return <user/> as the root element."
55   - # The +resource+ parameter passed into the block is a ResourceOptions object, and
56   - # is used to configure the tests for the details of your resources.
57   - #
58   - def should_be_restful(&blk) # :yields: resource
59   - warn "[DEPRECATION] should_be_restful is deprecated. Please see http://thoughtbot.lighthouseapp.com/projects/5807/tickets/78 for more information."
60   -
61   - resource = ResourceOptions.new
62   - blk.call(resource)
63   - resource.normalize!(self)
64   -
65   - resource.formats.each do |format|
66   - resource.actions.each do |action|
67   - if self.respond_to? :"make_#{action}_#{format}_tests"
68   - self.send(:"make_#{action}_#{format}_tests", resource)
69   - else
70   - should "test #{action} #{format}" do
71   - flunk "Test for #{action} as #{format} not implemented"
72   - end
73   - end
74   - end
75   - end
76   - end
77   -
78 27 # :section: Test macros
79 28 # Macro that creates a test asserting that the flash contains the given value.
80 29 # val can be a String, a Regex, or nil (indicating that the flash should not be set)
233 lib/shoulda/controller/resource_options.rb
... ... @@ -1,233 +0,0 @@
1   -module Shoulda # :nodoc:
2   - module Controller
3   - # Formats tested by #should_be_restful. Defaults to [:html, :xml]
4   - VALID_FORMATS = Dir.glob(File.join(File.dirname(__FILE__), 'formats', '*.rb')).map { |f| File.basename(f, '.rb') }.map(&:to_sym) # :doc:
5   - VALID_FORMATS.each {|f| require "shoulda/controller/formats/#{f}"}
6   -
7   - # Actions tested by #should_be_restful
8   - VALID_ACTIONS = [:index, :show, :new, :edit, :create, :update, :destroy] # :doc:
9   -
10   - # A ResourceOptions object is passed into should_be_restful in order to configure the tests for your controller.
11   - #
12   - # Example:
13   - # class UsersControllerTest < Test::Unit::TestCase
14   - # fixtures :all
15   - #
16   - # def setup
17   - # ...normal setup code...
18   - # @user = User.find(:first)
19   - # end
20   - #
21   - # should_be_restful do |resource|
22   - # resource.identifier = :id
23   - # resource.klass = User
24   - # resource.object = :user
25   - # resource.parent = []
26   - # resource.actions = [:index, :show, :new, :edit, :update, :create, :destroy]
27   - # resource.formats = [:html, :xml]
28   - #
29   - # resource.create.params = { :name => "bob", :email => 'bob@bob.com', :age => 13}
30   - # resource.update.params = { :name => "sue" }
31   - #
32   - # resource.create.redirect = "user_url(@user)"
33   - # resource.update.redirect = "user_url(@user)"
34   - # resource.destroy.redirect = "users_url"
35   - #
36   - # resource.create.flash = /created/i
37   - # resource.update.flash = /updated/i
38   - # resource.destroy.flash = /removed/i
39   - # end
40   - # end
41   - #
42   - # Whenever possible, the resource attributes will be set to sensible defaults.
43   - #
44   - class ResourceOptions
45   - # Configuration options for the create, update, destroy actions under should_be_restful
46   - class ActionOptions
47   - # String evaled to get the target of the redirection.
48   - # All of the instance variables set by the controller will be available to the
49   - # evaled code.
50   - #
51   - # Example:
52   - # resource.create.redirect = "user_url(@user.company, @user)"
53   - #
54   - # Defaults to a generated url based on the name of the controller, the action, and the resource.parents list.
55   - attr_accessor :redirect
56   -
57   - # String or Regexp describing a value expected in the flash. Will match against any flash key.
58   - #
59   - # Defaults:
60   - # destroy:: /removed/
61   - # create:: /created/
62   - # update:: /updated/
63   - attr_accessor :flash
64   -
65   - # Hash describing the params that should be sent in with this action.
66   - attr_accessor :params
67   - end
68   -
69   - # Configuration options for the denied actions under should_be_restful
70   - #
71   - # Example:
72   - # context "The public" do
73   - # setup do
74   - # @request.session[:logged_in] = false
75   - # end
76   - #
77   - # should_be_restful do |resource|
78   - # resource.parent = :user
79   - #
80   - # resource.denied.actions = [:index, :show, :edit, :new, :create, :update, :destroy]
81   - # resource.denied.flash = /get outta here/i
82   - # resource.denied.redirect = 'new_session_url'
83   - # end
84   - # end
85   - #
86   - class DeniedOptions
87   - # String evaled to get the target of the redirection.
88   - # All of the instance variables set by the controller will be available to the
89   - # evaled code.
90   - #
91   - # Example:
92   - # resource.create.redirect = "user_url(@user.company, @user)"
93   - attr_accessor :redirect
94   -
95   - # String or Regexp describing a value expected in the flash. Will match against any flash key.
96   - #
97   - # Example:
98   - # resource.create.flash = /created/
99   - attr_accessor :flash
100   -
101   - # Actions that should be denied (only used by resource.denied). <i>Note that these actions will
102   - # only be tested if they are also listed in +resource.actions+</i>
103   - # The special value of :all will deny all of the REST actions.
104   - attr_accessor :actions
105   - end
106   -
107   - # Name of key in params that references the primary key.
108   - # Will almost always be :id (default), unless you are using a plugin or have patched rails.
109   - attr_accessor :identifier
110   -
111   - # Name of the ActiveRecord class this resource is responsible for. Automatically determined from
112   - # test class if not explicitly set. UserTest => "User"
113   - attr_accessor :klass
114   -
115   - # Name of the instantiated ActiveRecord object that should be used by some of the tests.
116   - # Defaults to the underscored name of the AR class. CompanyManager => :company_manager
117   - attr_accessor :object
118   -
119   - # Name of the parent AR objects. Can be set as parent= or parents=, and can take either
120   - # the name of the parent resource (if there's only one), or an array of names (if there's
121   - # more than one).
122   - #
123   - # Example:
124   - # # in the routes...
125   - # map.resources :companies do
126   - # map.resources :people do
127   - # map.resources :limbs
128   - # end
129   - # end
130   - #
131   - # # in the tests...
132   - # class PeopleControllerTest < Test::Unit::TestCase
133   - # should_be_restful do |resource|
134   - # resource.parent = :companies
135   - # end
136   - # end
137   - #
138   - # class LimbsControllerTest < Test::Unit::TestCase
139   - # should_be_restful do |resource|
140   - # resource.parents = [:companies, :people]
141   - # end
142   - # end
143   - attr_accessor :parent
144   - alias parents parent
145   - alias parents= parent=
146   -
147   - # Actions that should be tested. Must be a subset of VALID_ACTIONS (default).
148   - # Tests for each actionw will only be generated if the action is listed here.
149   - # The special value of :all will test all of the REST actions.
150   - #
151   - # Example (for a read-only controller):
152   - # resource.actions = [:show, :index]
153   - attr_accessor :actions
154   -
155   - # Formats that should be tested. Must be a subset of VALID_FORMATS (default).
156   - # Each action will be tested against the formats listed here. The special value
157   - # of :all will test all of the supported formats.
158   - #
159   - # Example:
160   - # resource.actions = [:html, :xml]
161   - attr_accessor :formats
162   -
163   - # ActionOptions object specifying options for the create action.
164   - attr_accessor :create
165   -
166   - # ActionOptions object specifying options for the update action.
167   - attr_accessor :update
168   -
169   - # ActionOptions object specifying options for the desrtoy action.
170   - attr_accessor :destroy
171   -
172   - # DeniedOptions object specifying which actions should return deny a request, and what should happen in that case.
173   - attr_accessor :denied
174   -
175   - def initialize # :nodoc:
176   - @create = ActionOptions.new
177   - @update = ActionOptions.new
178   - @destroy = ActionOptions.new
179   - @denied = DeniedOptions.new
180   -
181   - @create.flash ||= /created/i
182   - @update.flash ||= /updated/i
183   - @destroy.flash ||= /removed/i
184   - @denied.flash ||= /denied/i
185   -
186   - @create.params ||= {}
187   - @update.params ||= {}
188   -
189   - @actions = VALID_ACTIONS
190   - @formats = VALID_FORMATS
191   - @denied.actions = []
192   - end
193   -
194   - def normalize!(target) # :nodoc:
195   - @denied.actions = VALID_ACTIONS if @denied.actions == :all
196   - @actions = VALID_ACTIONS if @actions == :all
197   - @formats = VALID_FORMATS if @formats == :all
198   -
199   - @denied.actions = @denied.actions.map(&:to_sym)
200   - @actions = @actions.map(&:to_sym)
201   - @formats = @formats.map(&:to_sym)
202   -
203   - ensure_valid_members(@actions, VALID_ACTIONS, 'actions')
204   - ensure_valid_members(@denied.actions, VALID_ACTIONS, 'denied.actions')
205   - ensure_valid_members(@formats, VALID_FORMATS, 'formats')
206   -
207   - @identifier ||= :id
208   - @klass ||= target.name.gsub(/ControllerTest$/, '').singularize.constantize
209   - @object ||= @klass.name.tableize.singularize
210   - @parent ||= []
211   - @parent = [@parent] unless @parent.is_a? Array
212   -
213   - collection_helper = [@parent, @object.to_s.pluralize, 'url'].flatten.join('_')
214   - collection_args = @parent.map {|n| "@#{object}.#{n}"}.join(', ')
215   - @destroy.redirect ||= "#{collection_helper}(#{collection_args})"
216   -
217   - member_helper = [@parent, @object, 'url'].flatten.join('_')
218   - member_args = [@parent.map {|n| "@#{object}.#{n}"}, "@#{object}"].flatten.join(', ')
219   - @create.redirect ||= "#{member_helper}(#{member_args})"
220   - @update.redirect ||= "#{member_helper}(#{member_args})"
221   - @denied.redirect ||= "new_session_url"
222   - end
223   -
224   - private
225   -
226   - def ensure_valid_members(ary, valid_members, name) # :nodoc:
227   - invalid = ary - valid_members
228   - raise ArgumentError, "Unsupported #{name}: #{invalid.inspect}" unless invalid.empty?
229   - end
230   - end
231   - end
232   -end
233   -
21 test/functional/posts_controller_test.rb
@@ -33,32 +33,11 @@ def setup
33 33 should_route :get, '/users/5/posts/new', :action => :new, :user_id => 5
34 34 should_route :put, '/users/5/posts/1', :action => :update, :id => 1, :user_id => 5
35 35
36   - context "The public" do
37   - setup do
38   - @request.session[:logged_in] = false
39   - end
40   -
41   - should_be_restful do |resource|
42   - resource.parent = :user
43   -
44   - resource.denied.actions = [:index, :show, :edit, :new, :create, :update, :destroy]
45   - resource.denied.flash = /what/i
46   - resource.denied.redirect = '"/"'
47   - end
48   - end
49   -
50 36 context "Logged in" do
51 37 setup do
52 38 @request.session[:logged_in] = true
53 39 end
54 40
55   - should_be_restful do |resource|
56   - resource.parent = :user
57   -
58   - resource.create.params = { :title => "first post", :body => 'blah blah blah'}
59   - resource.update.params = { :title => "changed" }
60   - end
61   -
62 41 context "viewing posts for a user" do
63 42 setup do
64 43 get :index, :user_id => users(:first)
19 test/functional/users_controller_test.rb
@@ -16,23 +16,4 @@ def setup
16 16
17 17 should_filter_params :ssn
18 18
19   - should_be_restful do |resource|
20   - resource.identifier = :id
21   - resource.klass = User
22   - resource.object = :user
23   - resource.parent = []
24   - resource.actions = [:index, :show, :new, :edit, :update, :create, :destroy]
25   - resource.formats = [:html, :xml]
26   -
27   - resource.create.params = { :name => "bob", :email => 'bob@bob.com', :age => 13, :ssn => "123456789"}
28   - resource.update.params = { :name => "sue" }
29   -
30   - resource.create.redirect = "user_url(@user)"
31   - resource.update.redirect = "user_url(@user)"
32   - resource.destroy.redirect = "users_url"
33   -
34   - resource.create.flash = /created/i
35   - resource.update.flash = /updated/i
36   - resource.destroy.flash = /removed/i
37   - end
38 19 end

0 comments on commit 33f547c

Please sign in to comment.
Something went wrong with that request. Please try again.