rc_rails 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG +355 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock.development +117 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +71 -0
  7. data/Rakefile +33 -0
  8. data/Todo.txt +1 -0
  9. data/lib/rc_rails.rb +9 -0
  10. data/lib/resources_controller/actions.rb +147 -0
  11. data/lib/resources_controller/active_record/saved.rb +15 -0
  12. data/lib/resources_controller/helper.rb +123 -0
  13. data/lib/resources_controller/include_actions.rb +37 -0
  14. data/lib/resources_controller/named_route_helper.rb +154 -0
  15. data/lib/resources_controller/railtie.rb +14 -0
  16. data/lib/resources_controller/request_path_introspection.rb +83 -0
  17. data/lib/resources_controller/resource_methods.rb +32 -0
  18. data/lib/resources_controller/singleton_actions.rb +21 -0
  19. data/lib/resources_controller/specification.rb +119 -0
  20. data/lib/resources_controller/version.rb +3 -0
  21. data/lib/resources_controller.rb +849 -0
  22. data/resources_controller.gemspec +29 -0
  23. data/spec/app/database.yml +5 -0
  24. data/spec/app/views/accounts/show.html.erb +0 -0
  25. data/spec/app/views/addresses/edit.html.erb +0 -0
  26. data/spec/app/views/addresses/index.html.erb +0 -0
  27. data/spec/app/views/addresses/new.html.erb +0 -0
  28. data/spec/app/views/addresses/show.html.erb +0 -0
  29. data/spec/app/views/admin/forums/create.html.erb +0 -0
  30. data/spec/app/views/admin/forums/destroy.html.erb +0 -0
  31. data/spec/app/views/admin/forums/edit.html.erb +0 -0
  32. data/spec/app/views/admin/forums/index.html.erb +0 -0
  33. data/spec/app/views/admin/forums/new.html.erb +0 -0
  34. data/spec/app/views/admin/forums/show.html.erb +0 -0
  35. data/spec/app/views/admin/forums/update.html.erb +0 -0
  36. data/spec/app/views/comments/edit.html.erb +0 -0
  37. data/spec/app/views/comments/index.html.erb +0 -0
  38. data/spec/app/views/comments/new.html.erb +0 -0
  39. data/spec/app/views/comments/show.html.erb +0 -0
  40. data/spec/app/views/forum_posts/edit.html.erb +0 -0
  41. data/spec/app/views/forum_posts/index.html.erb +0 -0
  42. data/spec/app/views/forum_posts/new.html.erb +0 -0
  43. data/spec/app/views/forum_posts/show.html.erb +0 -0
  44. data/spec/app/views/forums/create.html.erb +0 -0
  45. data/spec/app/views/forums/destroy.html.erb +0 -0
  46. data/spec/app/views/forums/edit.html.erb +0 -0
  47. data/spec/app/views/forums/index.html.erb +0 -0
  48. data/spec/app/views/forums/new.html.erb +0 -0
  49. data/spec/app/views/forums/show.html.erb +0 -0
  50. data/spec/app/views/forums/update.html.erb +0 -0
  51. data/spec/app/views/infos/edit.html.erb +0 -0
  52. data/spec/app/views/infos/show.html.erb +0 -0
  53. data/spec/app/views/interests/index.html.erb +0 -0
  54. data/spec/app/views/interests/show.html.erb +0 -0
  55. data/spec/app/views/owners/edit.html.erb +0 -0
  56. data/spec/app/views/owners/new.html.erb +0 -0
  57. data/spec/app/views/owners/show.html.erb +0 -0
  58. data/spec/app/views/tags/index.html.erb +0 -0
  59. data/spec/app/views/tags/new.html.erb +0 -0
  60. data/spec/app/views/tags/show.html.erb +0 -0
  61. data/spec/app/views/users/edit.html.erb +0 -0
  62. data/spec/app/views/users/index.html.erb +0 -0
  63. data/spec/app/views/users/show.html.erb +0 -0
  64. data/spec/app.rb +315 -0
  65. data/spec/controllers/accounts_controller_spec.rb +77 -0
  66. data/spec/controllers/addresses_controller_spec.rb +346 -0
  67. data/spec/controllers/admin_forums_controller_spec.rb +638 -0
  68. data/spec/controllers/comments_controller_spec.rb +380 -0
  69. data/spec/controllers/comments_controller_with_models_spec.rb +202 -0
  70. data/spec/controllers/forum_posts_controller_spec.rb +426 -0
  71. data/spec/controllers/forums_controller_spec.rb +694 -0
  72. data/spec/controllers/infos_controller_spec.rb +71 -0
  73. data/spec/controllers/interests_controller_via_forum_spec.rb +80 -0
  74. data/spec/controllers/interests_controller_via_user_spec.rb +114 -0
  75. data/spec/controllers/owners_controller_spec.rb +277 -0
  76. data/spec/controllers/resource_saved_spec.rb +47 -0
  77. data/spec/controllers/resource_service_in_forums_controller_spec.rb +37 -0
  78. data/spec/controllers/resource_service_in_infos_controller_spec.rb +36 -0
  79. data/spec/controllers/resource_service_in_interests_controller_via_forum_spec.rb +51 -0
  80. data/spec/controllers/tags_controller_spec.rb +83 -0
  81. data/spec/controllers/tags_controller_via_account_info_spec.rb +131 -0
  82. data/spec/controllers/tags_controller_via_forum_post_comment_spec.rb +144 -0
  83. data/spec/controllers/tags_controller_via_forum_post_spec.rb +133 -0
  84. data/spec/controllers/tags_controller_via_forum_spec.rb +173 -0
  85. data/spec/controllers/tags_controller_via_user_address_spec.rb +130 -0
  86. data/spec/controllers/users_controller_spec.rb +248 -0
  87. data/spec/lib/action_view_helper_spec.rb +143 -0
  88. data/spec/lib/bug_0001_spec.rb +22 -0
  89. data/spec/lib/include_actions_spec.rb +35 -0
  90. data/spec/lib/load_enclosing_resources_spec.rb +245 -0
  91. data/spec/lib/request_path_introspection_spec.rb +130 -0
  92. data/spec/lib/resource_methods_spec.rb +204 -0
  93. data/spec/lib/resources_controller_spec.rb +57 -0
  94. data/spec/models/comment_saved_spec.rb +24 -0
  95. data/spec/rspec_generator_task.rb +105 -0
  96. data/spec/spec_helper.rb +17 -0
  97. data/spec/verify_rcov.rb +52 -0
  98. metadata +193 -0
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ module TagsViaForumSpecHelper
4
+ def setup_mocks
5
+ @forum = mock('Forum')
6
+ @forum_tags = mock('forum_tags assoc')
7
+ Forum.stub!(:find).and_return(@forum)
8
+ @forum.stub!(:tags).and_return(@forum_tags)
9
+ @forum.stub!(:to_param).and_return('1')
10
+ end
11
+ end
12
+
13
+ describe TagsController do
14
+ describe "Routing shortcuts for Tags via Forum (forums/1/tags/2) should map" do
15
+ include TagsViaForumSpecHelper
16
+
17
+ before(:each) do
18
+ setup_mocks
19
+ @tag = mock('Tag')
20
+ @tag.stub!(:to_param).and_return('2')
21
+ @forum_tags.stub!(:find).and_return(@tag)
22
+
23
+ get :show, :forum_id => "1", :id => "2"
24
+ end
25
+
26
+ it "resources_path to /forums/1/tags" do
27
+ controller.resources_path.should == '/forums/1/tags'
28
+ end
29
+
30
+ it "resource_path to /forums/1/tags/2" do
31
+ controller.resource_path.should == '/forums/1/tags/2'
32
+ end
33
+
34
+ it "resource_path(9) to /forums/1/tags/9" do
35
+ controller.resource_path(9).should == '/forums/1/tags/9'
36
+ end
37
+
38
+ it "edit_resource_path to /forums/1/tags/2/edit" do
39
+ controller.edit_resource_path.should == '/forums/1/tags/2/edit'
40
+ end
41
+
42
+ it "edit_resource_path(9) to /forums/1/tags/9/edit" do
43
+ controller.edit_resource_path(9).should == '/forums/1/tags/9/edit'
44
+ end
45
+
46
+ it "new_resource_path to /forums/1/tags/new" do
47
+ controller.new_resource_path.should == '/forums/1/tags/new'
48
+ end
49
+
50
+ it "enclosing_resource_path to /forums/1" do
51
+ controller.enclosing_resource_path.should == "/forums/1"
52
+ end
53
+ end
54
+
55
+ describe "resource_service in TagsController via Forum" do
56
+
57
+ before(:each) do
58
+ @forum = Forum.create
59
+ @tag = Tag.create :taggable_id => @forum.id, :taggable_type => 'Forum'
60
+ @other_forum = Forum.create
61
+ @other_tag = Tag.create :taggable_id => @other_forum.id, :taggable_type => 'Forum'
62
+
63
+ get :new, :forum_id => @forum.id
64
+ @resource_service = controller.send :resource_service
65
+ end
66
+
67
+ it "should build new tag with @forum fk and type with new" do
68
+ resource = @resource_service.new
69
+ resource.should be_kind_of(Tag)
70
+ resource.taggable_id.should == @forum.id
71
+ resource.taggable_type.should == 'Forum'
72
+ end
73
+
74
+ it "should find @tag with find(@tag.id)" do
75
+ resource = @resource_service.find(@tag.id)
76
+ resource.should == @tag
77
+ end
78
+
79
+ it "should raise RecordNotFound with find(@other_tag.id)" do
80
+ lambda{ @resource_service.find(@other_tag.id) }.should raise_error(ActiveRecord::RecordNotFound)
81
+ end
82
+
83
+ it "should find only tags belonging to @forum with find(:all)" do
84
+ resources = @resource_service.find(:all)
85
+ resources.should be == Tag.find(:all, :conditions => "taggable_id = #{@forum.id} AND taggable_type = 'Forum'")
86
+ end
87
+ end
88
+
89
+ describe "Requesting /forums/1/tags using GET" do
90
+ include TagsViaForumSpecHelper
91
+
92
+ before(:each) do
93
+ setup_mocks
94
+ @tags = mock('Tags')
95
+ @forum_tags.stub!(:all).and_return(@tags)
96
+ end
97
+
98
+ def do_get
99
+ get :index, :forum_id => '1'
100
+ end
101
+
102
+ it "should find the forum" do
103
+ Forum.should_receive(:find).with('1').and_return(@forum)
104
+ do_get
105
+ end
106
+
107
+ it "should assign the found forum for the view" do
108
+ do_get
109
+ assigns[:forum].should == @forum
110
+ end
111
+
112
+ it "should assign the forum_tags association as the tags resource_service" do
113
+ @forum.should_receive(:tags).and_return(@forum_tags)
114
+ do_get
115
+ @controller.resource_service.should == @forum_tags
116
+ end
117
+ end
118
+
119
+ describe "Requesting /forums/1/tags/new using GET" do
120
+ include TagsViaForumSpecHelper
121
+
122
+ before(:each) do
123
+ setup_mocks
124
+ @tag = mock('Tag')
125
+ @forum_tags.stub!(:build).and_return(@tag)
126
+ end
127
+
128
+ def do_get
129
+ get :new, :forum_id => '1', :tag => {"name" => "hello"}
130
+ end
131
+
132
+ it "should find the forum" do
133
+ Forum.should_receive(:find).with('1').and_return(@forum)
134
+ do_get
135
+ end
136
+
137
+ it "should assign the found forum for the view" do
138
+ do_get
139
+ assigns[:forum].should == @forum
140
+ end
141
+
142
+ it "should assign the forum_tags association as the tags resource_service" do
143
+ @forum.should_receive(:tags).and_return(@forum_tags)
144
+ do_get
145
+ @controller.resource_service.should == @forum_tags
146
+ end
147
+
148
+ it "should render new template" do
149
+ do_get
150
+ response.should render_template('new')
151
+ end
152
+
153
+ it "should build a new tag with params" do
154
+ @forum_tags.should_receive(:build).with("name" => "hello").and_return(@tag)
155
+ do_get
156
+ end
157
+
158
+ it "should not save the new category" do
159
+ @tag.should_not_receive(:save)
160
+ do_get
161
+ end
162
+
163
+ it "should assign the new tag for the view" do
164
+ do_get
165
+ assigns[:tag].should equal(@tag)
166
+ end
167
+
168
+ it "should send :resource= to controller with @tag" do
169
+ controller.should_receive(:resource=).with(@tag)
170
+ do_get
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ module TagsViaUserAddressSpecHelper
4
+ def setup_mocks
5
+ @user = mock_model(User)
6
+ User.stub!(:find_by_login).and_return(@user)
7
+ @user.stub!(:to_param).and_return('dave')
8
+ @user_addresses = mock('user_addresses assoc')
9
+ @user.stub!(:addresses).and_return(@user_addresses)
10
+
11
+ @address = mock_model(Address)
12
+ @user_addresses.stub!(:find).and_return(@address)
13
+ @address.stub!(:to_param).and_return('2')
14
+ @address_tags = mock('address_tags assoc')
15
+ @address.stub!(:tags).and_return(@address_tags)
16
+ end
17
+ end
18
+
19
+ describe TagsController do
20
+ describe "Routing shortcuts for Tags via User and Address (users/dave/addresses/2/tags/3) should map" do
21
+ include TagsViaUserAddressSpecHelper
22
+
23
+ before(:each) do
24
+ setup_mocks
25
+ @tag = mock_model(Tag)
26
+ @tag.stub!(:to_param).and_return('3')
27
+ @address_tags.stub!(:find).and_return(@tag)
28
+
29
+ get :show, :user_id => "dave", :address_id => "2", :id => "3"
30
+ end
31
+
32
+ it "resources_path to /users/dave/addresses/2/tags" do
33
+ controller.resources_path.should == '/users/dave/addresses/2/tags'
34
+ end
35
+
36
+ it "resource_path to /users/dave/addresses/2/tags/3" do
37
+ controller.resource_path.should == '/users/dave/addresses/2/tags/3'
38
+ end
39
+
40
+ it "resource_path(9) to /users/dave/addresses/2/tags/9" do
41
+ controller.resource_path(9).should == '/users/dave/addresses/2/tags/9'
42
+ end
43
+
44
+ it "edit_resource_path to /users/dave/addresses/2/tags/3/edit" do
45
+ controller.edit_resource_path.should == '/users/dave/addresses/2/tags/3/edit'
46
+ end
47
+
48
+ it "edit_resource_path(9) to /users/dave/addresses/2/tags/9/edit" do
49
+ controller.edit_resource_path(9).should == '/users/dave/addresses/2/tags/9/edit'
50
+ end
51
+
52
+ it "new_resource_path to /users/dave/addresses/2/tags/new" do
53
+ controller.new_resource_path.should == '/users/dave/addresses/2/tags/new'
54
+ end
55
+
56
+ it "enclosing_resource_path to /users/dave/addresses/2" do
57
+ controller.enclosing_resource_path.should == "/users/dave/addresses/2"
58
+ end
59
+ end
60
+
61
+ describe "resource_service in TagsController via User and Address" do
62
+
63
+ before(:each) do
64
+ @user = User.create
65
+ @address = Address.create :user_id => @user.id
66
+ @tag = Tag.create :taggable_id => @address.id, :taggable_type => 'Address'
67
+ @other_address = Address.create :user_id => @user.id
68
+ @other_tag = Tag.create :taggable_id => @other_address.id, :taggable_type => 'Address'
69
+
70
+ get :index, :user_id => @user.id, :address_id => @address.id
71
+ @resource_service = controller.send :resource_service
72
+ end
73
+
74
+ it "should build new tag with @address fk and type with new" do
75
+ resource = @resource_service.new
76
+ resource.should be_kind_of(Tag)
77
+ resource.taggable_id.should == @address.id
78
+ resource.taggable_type.should == 'Address'
79
+ end
80
+
81
+ it "should find @tag with find(@tag.id)" do
82
+ resource = @resource_service.find(@tag.id)
83
+ resource.should == @tag
84
+ end
85
+
86
+ it "should raise RecordNotFound with find(@other_tag.id)" do
87
+ lambda{ @resource_service.find(@other_tag.id) }.should raise_error(ActiveRecord::RecordNotFound)
88
+ end
89
+
90
+ it "should find only tags belonging to @address with find(:all)" do
91
+ resources = @resource_service.find(:all)
92
+ resources.should be == Tag.find(:all, :conditions => "taggable_id = #{@address.id} AND taggable_type = 'Address'")
93
+ end
94
+ end
95
+
96
+ describe "Requesting /users/dave/addresses/2/tags using GET" do
97
+ include TagsViaUserAddressSpecHelper
98
+
99
+ before(:each) do
100
+ setup_mocks
101
+ @tags = mock('Tags')
102
+ @address_tags.stub!(:all).and_return(@tags)
103
+ end
104
+
105
+ def do_get
106
+ get :index, :user_id => "dave", :address_id => '2'
107
+ end
108
+
109
+ it "should find the user" do
110
+ User.should_receive(:find_by_login).with('dave').and_return(@user)
111
+ do_get
112
+ end
113
+
114
+ it "should find the address" do
115
+ @user_addresses.should_receive(:find).with('2').and_return(@address)
116
+ do_get
117
+ end
118
+
119
+ it "should assign the found address for the view" do
120
+ do_get
121
+ assigns[:address].should == @address
122
+ end
123
+
124
+ it "should assign the address_tags association as the tags resource_service" do
125
+ @address.should_receive(:tags).and_return(@address_tags)
126
+ do_get
127
+ @controller.resource_service.should == @address_tags
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,248 @@
1
+ require 'spec_helper'
2
+
3
+ describe UsersController, "routing" do
4
+
5
+ it "should route to { :controller => 'users', action => 'index' } from GET /users" do
6
+ {:get => "/users"}.should route_to(:controller => "users", :action => "index")
7
+ end
8
+
9
+ it "should route to { :controller => 'users', action => 'new' } from GET /users/new" do
10
+ {:get => "/users/new"}.should route_to(:controller => "users", :action => "new")
11
+ end
12
+
13
+ it "should route to { :controller => 'users', action => 'create' } from POST /users" do
14
+ {:post => "/users"}.should route_to(:controller => "users", :action => "create")
15
+ end
16
+
17
+ it "should route to { :controller => 'users', action => 'show', id => '1' } from GET /users/dave" do
18
+ {:get => "/users/dave"}.should route_to(:controller => "users", :action => "show", :id => "dave")
19
+ end
20
+
21
+ it "should route to { :controller => 'users', action => 'edit', id => '1' } from GET /users/dave/edit" do
22
+ {:get => "/users/dave/edit"}.should route_to(:controller => "users", :action => "edit", :id => "dave")
23
+ end
24
+
25
+ it "should route to { :controller => 'users', action => 'update', id => '1' } from PUT /users/dave" do
26
+ {:put => "/users/dave"}.should route_to(:controller => "users", :action => "update", :id => "dave")
27
+ end
28
+
29
+ it "should route to { :controller => 'users', action => 'destroy', id => '1' } from DELETE /users/dave" do
30
+ {:delete => "/users/dave"}.should route_to(:controller => "users", :action => "destroy", :id => "dave")
31
+ end
32
+
33
+ end
34
+
35
+ describe UsersController, "handling GET /users" do
36
+
37
+ before do
38
+ @user = mock_model(User)
39
+ User.stub!(:all).and_return([@user])
40
+ end
41
+
42
+ def do_get
43
+ get :index
44
+ end
45
+
46
+ it "should be successful" do
47
+ do_get
48
+ response.should be_success
49
+ end
50
+
51
+ it "should render index template" do
52
+ do_get
53
+ response.should render_template('index')
54
+ end
55
+
56
+ it "should find all users" do
57
+ User.should_receive(:all).and_return([@user])
58
+ do_get
59
+ end
60
+
61
+ it "should assign the found users for the view" do
62
+ do_get
63
+ assigns[:users].should == [@user]
64
+ end
65
+ end
66
+
67
+ describe UsersController, "handling GET /users.xml" do
68
+
69
+ before do
70
+ @user = mock_model(User, :to_xml => "XML")
71
+ User.stub!(:all).and_return(@user)
72
+ end
73
+
74
+ def do_get
75
+ @request.env["HTTP_ACCEPT"] = "application/xml"
76
+ get :index
77
+ end
78
+
79
+ it "should be successful" do
80
+ do_get
81
+ response.should be_success
82
+ end
83
+
84
+ it "should find all users" do
85
+ User.should_receive(:all).and_return([@user])
86
+ do_get
87
+ end
88
+
89
+ it "should render the found users as xml" do
90
+ @user.should_receive(:to_xml).and_return("XML")
91
+ do_get
92
+ response.body.should == "XML"
93
+ end
94
+ end
95
+
96
+ describe UsersController, "handling GET /users/dave" do
97
+
98
+ before do
99
+ @user = mock_model(User)
100
+ User.stub!(:find_by_login).and_return(@user)
101
+ end
102
+
103
+ def do_get
104
+ get :show, :id => "dave"
105
+ end
106
+
107
+ it "should be successful" do
108
+ do_get
109
+ response.should be_success
110
+ end
111
+
112
+ it "should render show template" do
113
+ do_get
114
+ response.should render_template('show')
115
+ end
116
+
117
+ it "should find the user requested" do
118
+ User.should_receive(:find_by_login).with("dave").and_return(@user)
119
+ do_get
120
+ end
121
+
122
+ it "should assign the found user for the view" do
123
+ do_get
124
+ assigns[:user].should equal(@user)
125
+ end
126
+ end
127
+
128
+ describe UsersController, "handling GET /users/dave.xml" do
129
+
130
+ before do
131
+ @user = mock_model(User, :to_xml => "XML")
132
+ User.stub!(:find_by_login).and_return(@user)
133
+ end
134
+
135
+ def do_get
136
+ @request.env["HTTP_ACCEPT"] = "application/xml"
137
+ get :show, :id => "dave"
138
+ end
139
+
140
+ it "should be successful" do
141
+ do_get
142
+ response.should be_success
143
+ end
144
+
145
+ it "should find the user requested" do
146
+ User.should_receive(:find_by_login).with("dave").and_return(@user)
147
+ do_get
148
+ end
149
+
150
+ it "should render the found user as xml" do
151
+ @user.should_receive(:to_xml).and_return("XML")
152
+ do_get
153
+ response.body.should == "XML"
154
+ end
155
+ end
156
+
157
+ describe UsersController, "handling GET /users/new" do
158
+ it "should be unknown action" do
159
+ lambda{ get :new }.should raise_error(ActionView::MissingTemplate)
160
+ end
161
+ end
162
+
163
+ describe UsersController, "handling GET /users/dave/edit" do
164
+
165
+ before do
166
+ @user = mock_model(User)
167
+ User.stub!(:find_by_login).and_return(@user)
168
+ end
169
+
170
+ def do_get
171
+ get :edit, :id => "dave"
172
+ end
173
+
174
+ it "should be successful" do
175
+ do_get
176
+ response.should be_success
177
+ end
178
+
179
+ it "should render edit template" do
180
+ do_get
181
+ response.should render_template('edit')
182
+ end
183
+
184
+ it "should find the user requested" do
185
+ User.should_receive(:find_by_login).and_return(@user)
186
+ do_get
187
+ end
188
+
189
+ it "should assign the found User for the view" do
190
+ do_get
191
+ assigns[:user].should equal(@user)
192
+ end
193
+ end
194
+
195
+ describe UsersController, "handling POST /users" do
196
+ it "should be unknown action" do
197
+ lambda{ post :create }.should raise_error(ActionController::RoutingError)
198
+ end
199
+ end
200
+
201
+ describe UsersController, "handling PUT /users/dave" do
202
+
203
+ before do
204
+ @user = mock_model(User, :to_param => "dave")
205
+ User.stub!(:find_by_login).and_return(@user)
206
+ end
207
+
208
+ def put_with_successful_update
209
+ @user.should_receive(:update_attributes).and_return(true)
210
+ put :update, :id => "dave"
211
+ end
212
+
213
+ def put_with_failed_update
214
+ @user.should_receive(:update_attributes).and_return(false)
215
+ put :update, :id => "dave"
216
+ end
217
+
218
+ it "should find the user requested" do
219
+ User.should_receive(:find_by_login).with("dave").and_return(@user)
220
+ put_with_successful_update
221
+ end
222
+
223
+ it "should update the found user" do
224
+ put_with_successful_update
225
+ assigns(:user).should equal(@user)
226
+ end
227
+
228
+ it "should assign the found user for the view" do
229
+ put_with_successful_update
230
+ assigns(:user).should equal(@user)
231
+ end
232
+
233
+ it "should redirect to the user on successful update" do
234
+ put_with_successful_update
235
+ response.should redirect_to(user_url("dave"))
236
+ end
237
+
238
+ it "should re-render 'edit' on failed update" do
239
+ put_with_failed_update
240
+ response.should render_template('edit')
241
+ end
242
+ end
243
+
244
+ describe UsersController, "handling DELETE /users/dave" do
245
+ it "should be unknown action" do
246
+ lambda{ delete :destroy, :id => "dave" }.should raise_error(::AbstractController::ActionNotFound)
247
+ end
248
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ class ViewWithResourcesControllerHelper < ActionView::Base
4
+ include ResourcesController::Helper
5
+ end
6
+
7
+ describe "ActionView with resources_controller Helper" do
8
+ before do
9
+ @view = ViewWithResourcesControllerHelper.new
10
+ @controller = mock('Controller')
11
+ @view.controller = @controller
12
+ end
13
+
14
+ def self.it_should_forward_to_controller(msg, *args)
15
+ it "should forward ##{msg}#{args.size > 0 ? "(#{args.join(',')})" : ""} to controller" do
16
+ @controller.should_receive(msg).with(*args)
17
+ @view.send(msg, *args)
18
+ end
19
+ end
20
+
21
+ it_should_forward_to_controller :resource_name
22
+ it_should_forward_to_controller :resources_name
23
+ it_should_forward_to_controller :resource
24
+ it_should_forward_to_controller :resources
25
+ it_should_forward_to_controller :enclosing_resource
26
+ it_should_forward_to_controller :enclosing_resource_name
27
+
28
+ it 'should not forward unknown url helper to controller' do
29
+ @controller.stub!(:resource_named_route_helper_method?).and_return(false)
30
+ @controller.should_not_receive(:resource_foo_path)
31
+ lambda { @view.send(:resource_foo_path) }.should raise_error(NoMethodError)
32
+ end
33
+
34
+ it "#error_messages_for_resource should call error_messages_for with resource_name" do
35
+ @controller.should_receive(:resource_name).and_return('name')
36
+ @view.should_receive(:error_messages_for).with('name')
37
+ @view.error_messages_for_resource
38
+ end
39
+ end
40
+
41
+ describe "Helper#form_for_resource (when resource is new record)" do
42
+ before do
43
+ @view = ViewWithResourcesControllerHelper.new
44
+ @controller = mock('Controller')
45
+ @specification = mock('Specification')
46
+ @specification.stub!(:singleton?).and_return(false)
47
+ @resource = mock('Forum')
48
+ @resource = mock('Forum').as_null_object
49
+ @resource.stub!(:new_record?).and_return(true)
50
+ @controller.stub!(:resource).and_return(@resource)
51
+ @controller.stub!(:resource_name).and_return('forum')
52
+ @controller.stub!(:resources_path).and_return('/forums')
53
+ @controller.stub!(:resource_specification).and_return(@specification)
54
+ @controller.stub!(:resource_named_route_helper_method?).and_return(true)
55
+ @view.controller = @controller
56
+ end
57
+
58
+ it 'should call form_for with create form options' do
59
+ @view.should_receive(:form_for).with('forum', @resource, {:html => {:method => :post}, :url => '/forums'})
60
+ @view.form_for_resource{}
61
+ end
62
+
63
+ it 'when passed :url_options, they should be passed to the path generation' do
64
+ @view.should_receive(:resources_path).with({:foo => 'bar'}).and_return('/forums?foo=bar')
65
+ @view.should_receive(:form_for).with('forum', @resource, {:html => {:method => :post}, :url => '/forums?foo=bar'})
66
+ @view.form_for_resource(:url_options => {:foo => 'bar'}) {}
67
+ end
68
+
69
+ it 'when not passed :url_options, they should not be passed to the path generation' do
70
+ @view.should_receive(:resources_path).with().and_return('/forums')
71
+ @view.should_receive(:form_for).with('forum', @resource, {:html => {:method => :post}, :url => '/forums'})
72
+ @view.form_for_resource{}
73
+ end
74
+ end
75
+
76
+ describe "Helper#form_for_resource (when resource is new record) and resource is singleton" do
77
+ before do
78
+ @view = ViewWithResourcesControllerHelper.new
79
+ @controller = mock('Controller')
80
+ @specification = mock('Specification')
81
+ @specification.stub!(:singleton?).and_return(true)
82
+ @resource = mock('Account')
83
+ @resource = mock('Account').as_null_object
84
+ @resource.stub!(:new_record?).and_return(true)
85
+ @controller.stub!(:resource).and_return(@resource)
86
+ @controller.stub!(:resource_name).and_return('account')
87
+ @controller.stub!(:resource_path).and_return('/account')
88
+ @controller.stub!(:resource_specification).and_return(@specification)
89
+ @controller.stub!(:resource_named_route_helper_method?).and_return(true)
90
+ @view.controller = @controller
91
+ end
92
+
93
+ it 'should call form_for with create form options' do
94
+ @view.should_receive(:form_for).with('account', @resource, {:html => {:method => :post}, :url => '/account'})
95
+ @view.form_for_resource{}
96
+ end
97
+ end
98
+
99
+ describe "Helper#form_for_resource (when resource is existing record)" do
100
+ before do
101
+ @view = ViewWithResourcesControllerHelper.new
102
+ @controller = mock('Controller')
103
+ @specification = mock('Specification')
104
+ @specification.stub!(:singleton?).and_return(false)
105
+ @resource = mock('Forum').as_null_object
106
+ @resource.stub!(:new_record?).and_return(false)
107
+ @resource.stub!(:to_param).and_return("1")
108
+ @controller.stub!(:resource).and_return(@resource)
109
+ @controller.stub!(:resource_name).and_return('forum')
110
+ @controller.stub!(:resource_path).and_return('/forums/1')
111
+ @controller.stub!(:resource_specification).and_return(@specification)
112
+ @controller.stub!(:resource_named_route_helper_method?).and_return(true)
113
+ @view.controller = @controller
114
+ end
115
+
116
+ it 'should call form_for with update form options' do
117
+ @view.should_receive(:form_for).with('forum', @resource, {:html => {:method => :put}, :url => '/forums/1'})
118
+ @view.form_for_resource{}
119
+ end
120
+ end
121
+
122
+ describe "Helper#remote_form_for_resource (when resource is existing record)" do
123
+ before do
124
+ @view = ViewWithResourcesControllerHelper.new
125
+ @controller = mock('Controller')
126
+ @specification = mock('Specification')
127
+ @specification.stub!(:singleton?).and_return(false)
128
+ @resource = mock('Forum').as_null_object
129
+ @resource.stub!(:new_record?).and_return(false)
130
+ @resource.stub!(:to_param).and_return("1")
131
+ @controller.stub!(:resource).and_return(@resource)
132
+ @controller.stub!(:resource_name).and_return('forum')
133
+ @controller.stub!(:resource_path).and_return('/forums/1')
134
+ @controller.stub!(:resource_specification).and_return(@specification)
135
+ @controller.stub!(:resource_named_route_helper_method?).and_return(true)
136
+ @view.controller = @controller
137
+ end
138
+
139
+ it 'should call remote_form_for with update form options' do
140
+ @view.should_receive(:remote_form_for).with('forum', @resource, {:html => {:method => :put}, :url => '/forums/1'})
141
+ @view.remote_form_for_resource{}
142
+ end
143
+ end