easy_admin_ui 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -15
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/{assets/icons → app/assets/images/easy_admin_ui}/classify.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/connect.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/delete.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/disconnect.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/pencil.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/show.png +0 -0
- data/app/assets/stylesheets/easy_admin_ui/easy_admin_ui.sass +47 -0
- data/app/views/easy_admin_ui/destroy.js.erb +1 -0
- data/{templates → app/views}/easy_admin_ui/edit.html.erb +0 -0
- data/{templates → app/views}/easy_admin_ui/index.html.erb +0 -0
- data/{templates → app/views}/easy_admin_ui/new.html.erb +0 -0
- data/{templates → app/views}/easy_admin_ui/show.html.erb +0 -0
- data/easy_admin_ui.gemspec +80 -21
- data/lib/easy_admin_ui/core_ext.rb +1 -3
- data/lib/easy_admin_ui/rails/engine.rb +10 -0
- data/lib/easy_admin_ui/tasks.rb +0 -10
- data/lib/easy_admin_ui/view_helpers.rb +3 -3
- data/lib/easy_admin_ui.rb +1 -9
- data/vendor/plugins/make_resourceful/.gitignore +1 -0
- data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
- data/vendor/plugins/make_resourceful/LICENSE +7 -0
- data/vendor/plugins/make_resourceful/README.rdoc +239 -0
- data/vendor/plugins/make_resourceful/Rakefile +31 -0
- data/vendor/plugins/make_resourceful/VERSION +1 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +50 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
- data/vendor/plugins/make_resourceful/init.rb +3 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +63 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +385 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +402 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +101 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +84 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +185 -0
- data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +474 -0
- data/vendor/plugins/make_resourceful/spec/actions_spec.rb +310 -0
- data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
- data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
- data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
- data/vendor/plugins/make_resourceful/spec/integration_spec.rb +394 -0
- data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
- data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
- data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
- data/vendor/plugins/make_resourceful/spec/rspec-rails/LICENSE +37 -0
- data/vendor/plugins/make_resourceful/spec/rspec-rails/redirect_to.rb +113 -0
- data/vendor/plugins/make_resourceful/spec/rspec-rails/render_template.rb +90 -0
- data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
- data/vendor/plugins/make_resourceful/spec/spec_helper.rb +319 -0
- data/vendor/plugins/make_resourceful/spec/urls_spec.rb +282 -0
- data/vendor/plugins/make_resourceful/spec/views/things/create.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/destroy.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/edit.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/edit.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/index.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/index.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/new.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/new.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/show.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/show.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/update.rjs +1 -0
- metadata +75 -16
- data/assets/css/easy_admin_ui.css +0 -69
@@ -0,0 +1,314 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe 'Resourceful::Default::Responses', " with a _flash parameter for :error" do
|
4
|
+
include ControllerMocks
|
5
|
+
before :each do
|
6
|
+
mock_controller Resourceful::Default::Responses
|
7
|
+
@flash = {}
|
8
|
+
@controller.stubs(:flash).returns(@flash)
|
9
|
+
@params = {:_flash => {:error => 'Oh no, an error!'}}
|
10
|
+
@controller.stubs(:params).returns(@params)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set the flash for :error to the parameter's value when set_default_flash is called on :error" do
|
14
|
+
@controller.set_default_flash(:error, "Aw there's no error!")
|
15
|
+
@flash[:error].should == 'Oh no, an error!'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set the flash for :message to the default value when set_default_flash is called on :message" do
|
19
|
+
@controller.set_default_flash(:message, "All jim dandy!")
|
20
|
+
@flash[:message].should == 'All jim dandy!'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "shouldn't set the flash for :error when set_default_flash is called on :message" do
|
24
|
+
@controller.set_default_flash(:message, "All jim dandy!")
|
25
|
+
@flash[:error].should be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'Resourceful::Default::Responses', " with a _redirect parameter on :failure" do
|
30
|
+
include ControllerMocks
|
31
|
+
before :each do
|
32
|
+
mock_controller Resourceful::Default::Responses
|
33
|
+
@params = {:_redirect_on => {:failure => 'http://hamptoncatlin.com/'}}
|
34
|
+
@controller.stubs(:params).returns(@params)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set the redirect for :failure to the parameter's value when set_default_redirect is called on :failure" do
|
38
|
+
@controller.expects(:redirect_to).with('http://hamptoncatlin.com/')
|
39
|
+
@controller.set_default_redirect(:back, :status => :failure)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set the redirect for :success to the default value when set_default_redirect is called on :success" do
|
43
|
+
@controller.expects(:redirect_to).with(:back)
|
44
|
+
@controller.set_default_redirect(:back, :status => :success)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "shouldn't set the redirect for :failure when set_default_redirect is called on :success" do
|
48
|
+
@controller.expects(:redirect_to).with(:back)
|
49
|
+
@controller.expects(:redirect_to).with('http://hamptoncatlin.com/').never
|
50
|
+
@controller.set_default_redirect(:back, :status => :success)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set the default redirect for :success by default" do
|
54
|
+
@controller.expects(:redirect_to).with(:back)
|
55
|
+
@controller.set_default_redirect(:back)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'Resourceful::Default::Responses', ' for show' do
|
60
|
+
include ControllerMocks
|
61
|
+
before :each do
|
62
|
+
mock_kontroller
|
63
|
+
create_builder
|
64
|
+
made_resourceful(Resourceful::Default::Responses)
|
65
|
+
@builder.apply
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have an empty HTML response" do
|
69
|
+
responses[:show].find { |f, p| f == :html }[1].call.should == nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have an empty JS response" do
|
73
|
+
responses[:show].find { |f, p| f == :js }[1].call.should == nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'Resourceful::Default::Responses', ' for index' do
|
78
|
+
include ControllerMocks
|
79
|
+
before :each do
|
80
|
+
mock_kontroller
|
81
|
+
create_builder
|
82
|
+
made_resourceful(Resourceful::Default::Responses)
|
83
|
+
@builder.apply
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have an empty HTML response" do
|
87
|
+
responses[:index].find { |f, p| f == :html }[1].call.should == nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have an empty JS response" do
|
91
|
+
responses[:index].find { |f, p| f == :js }[1].call.should == nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'Resourceful::Default::Responses', ' for edit' do
|
96
|
+
include ControllerMocks
|
97
|
+
before :each do
|
98
|
+
mock_kontroller
|
99
|
+
create_builder
|
100
|
+
made_resourceful(Resourceful::Default::Responses)
|
101
|
+
@builder.apply
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have an empty HTML response" do
|
105
|
+
responses[:edit].find { |f, p| f == :html }[1].call.should == nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have an empty JS response" do
|
109
|
+
responses[:edit].find { |f, p| f == :js }[1].call.should == nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'Resourceful::Default::Responses', ' for new' do
|
114
|
+
include ControllerMocks
|
115
|
+
before :each do
|
116
|
+
mock_kontroller
|
117
|
+
create_builder
|
118
|
+
made_resourceful(Resourceful::Default::Responses)
|
119
|
+
@builder.apply
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should have an empty HTML response" do
|
123
|
+
responses[:new].find { |f, p| f == :html }[1].call.should == nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should have an empty JS response" do
|
127
|
+
responses[:new].find { |f, p| f == :js }[1].call.should == nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'Resourceful::Default::Responses', ' for show_fails' do
|
132
|
+
include ControllerMocks
|
133
|
+
before :each do
|
134
|
+
mock_controller Resourceful::Default::Callbacks
|
135
|
+
create_builder
|
136
|
+
made_resourceful(Resourceful::Default::Responses)
|
137
|
+
@builder.apply
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should give a 404 error for HTML" do
|
141
|
+
@controller.expects(:render).with(:text => "No item found", :status => 404)
|
142
|
+
@controller.scope(responses[:show_fails].find { |f, p| f == :html }[1]).call
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should give a 404 error for JS" do
|
146
|
+
@controller.expects(:render).with(:text => "No item found", :status => 404)
|
147
|
+
@controller.scope(responses[:show_fails].find { |f, p| f == :js }[1]).call
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should give a 404 error for XML" do
|
151
|
+
@controller.expects(:render).with(:text => "No item found", :status => 404)
|
152
|
+
@controller.scope(responses[:show_fails].find { |f, p| f == :xml }[1]).call
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe 'Resourceful::Default::Responses', ' for create' do
|
157
|
+
include ControllerMocks
|
158
|
+
before :each do
|
159
|
+
mock_controller Resourceful::Default::Callbacks
|
160
|
+
create_builder
|
161
|
+
made_resourceful(Resourceful::Default::Responses)
|
162
|
+
@builder.apply
|
163
|
+
|
164
|
+
[:set_default_flash, :set_default_redirect, :object_path].each(&@controller.method(:stubs))
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should have an empty JS response" do
|
168
|
+
responses[:create].find { |f, p| f == :js }[1].call.should == nil
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should flash a success message to :notice by default for HTML" do
|
172
|
+
@controller.expects(:set_default_flash).with(:notice, "Create successful!")
|
173
|
+
@controller.scope(responses[:create].find { |f, p| f == :html }[1]).call
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should redirect to object_path by default for HTML" do
|
177
|
+
@controller.stubs(:object_path).returns("/posts/12")
|
178
|
+
@controller.expects(:set_default_redirect).with("/posts/12")
|
179
|
+
@controller.scope(responses[:create].find { |f, p| f == :html }[1]).call
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'Resourceful::Default::Responses', ' for create_fails' do
|
184
|
+
include ControllerMocks
|
185
|
+
before :each do
|
186
|
+
mock_controller Resourceful::Default::Callbacks
|
187
|
+
create_builder
|
188
|
+
made_resourceful(Resourceful::Default::Responses)
|
189
|
+
@builder.apply
|
190
|
+
|
191
|
+
[:set_default_flash, :render].each(&@controller.method(:stubs))
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should have an empty JS response" do
|
195
|
+
responses[:create_fails].find { |f, p| f == :js }[1].call.should == nil
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should flash a failure message to :error by default for HTML" do
|
199
|
+
@controller.expects(:set_default_flash).with(:error, "There was a problem!")
|
200
|
+
@controller.scope(responses[:create_fails].find { |f, p| f == :html }[1]).call
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should render new with a 422 error for HTML" do
|
204
|
+
@controller.expects(:render).with(:action => :new, :status => 422)
|
205
|
+
@controller.scope(responses[:create_fails].find { |f, p| f == :html }[1]).call
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'Resourceful::Default::Responses', ' for update' do
|
210
|
+
include ControllerMocks
|
211
|
+
before :each do
|
212
|
+
mock_controller Resourceful::Default::Callbacks
|
213
|
+
create_builder
|
214
|
+
made_resourceful(Resourceful::Default::Responses)
|
215
|
+
@builder.apply
|
216
|
+
|
217
|
+
[:set_default_flash, :set_default_redirect, :object_path].each(&@controller.method(:stubs))
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should have an empty JS response" do
|
221
|
+
responses[:update].find { |f, p| f == :js }[1].call.should == nil
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should flash a success message to :notice by default for HTML" do
|
225
|
+
@controller.expects(:set_default_flash).with(:notice, "Save successful!")
|
226
|
+
@controller.scope(responses[:update].find { |f, p| f == :html }[1]).call
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should redirect to object_path by default for HTML" do
|
230
|
+
@controller.stubs(:object_path).returns("/posts/12")
|
231
|
+
@controller.expects(:set_default_redirect).with("/posts/12")
|
232
|
+
@controller.scope(responses[:update].find { |f, p| f == :html }[1]).call
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'Resourceful::Default::Responses', ' for update_fails' do
|
237
|
+
include ControllerMocks
|
238
|
+
before :each do
|
239
|
+
mock_controller Resourceful::Default::Callbacks
|
240
|
+
create_builder
|
241
|
+
made_resourceful(Resourceful::Default::Responses)
|
242
|
+
@builder.apply
|
243
|
+
|
244
|
+
[:set_default_flash, :render].each(&@controller.method(:stubs))
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should have an empty JS response" do
|
248
|
+
responses[:update_fails].find { |f, p| f == :js }[1].call.should == nil
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should flash a failure message to :error by default for HTML" do
|
252
|
+
@controller.expects(:set_default_flash).with(:error, "There was a problem saving!")
|
253
|
+
@controller.scope(responses[:update_fails].find { |f, p| f == :html }[1]).call
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should render edit with a 422 error for HTML" do
|
257
|
+
@controller.expects(:render).with(:action => :edit, :status => 422)
|
258
|
+
@controller.scope(responses[:update_fails].find { |f, p| f == :html }[1]).call
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
describe 'Resourceful::Default::Responses', ' for destroy' do
|
264
|
+
include ControllerMocks
|
265
|
+
before :each do
|
266
|
+
mock_controller Resourceful::Default::Callbacks
|
267
|
+
create_builder
|
268
|
+
made_resourceful(Resourceful::Default::Responses)
|
269
|
+
@builder.apply
|
270
|
+
|
271
|
+
[:set_default_flash, :set_default_redirect, :objects_path].each(&@controller.method(:stubs))
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should have an empty JS response" do
|
275
|
+
responses[:destroy].find { |f, p| f == :js }[1].call.should == nil
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should flash a success message to :notice by default for HTML" do
|
279
|
+
@controller.expects(:set_default_flash).with(:notice, "Record deleted!")
|
280
|
+
@controller.scope(responses[:destroy].find { |f, p| f == :html }[1]).call
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should redirect to objects_path by default for HTML" do
|
284
|
+
@controller.stubs(:objects_path).returns("/posts")
|
285
|
+
@controller.expects(:set_default_redirect).with("/posts")
|
286
|
+
@controller.scope(responses[:destroy].find { |f, p| f == :html }[1]).call
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe 'Resourceful::Default::Responses', ' for destroy_fails' do
|
291
|
+
include ControllerMocks
|
292
|
+
before :each do
|
293
|
+
mock_controller Resourceful::Default::Callbacks
|
294
|
+
create_builder
|
295
|
+
made_resourceful(Resourceful::Default::Responses)
|
296
|
+
@builder.apply
|
297
|
+
|
298
|
+
[:set_default_flash, :set_default_redirect, :render].each(&@controller.method(:stubs))
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should have an empty JS response" do
|
302
|
+
responses[:destroy_fails].find { |f, p| f == :js }[1].call.should == nil
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should flash a failure message to :error by default for HTML" do
|
306
|
+
@controller.expects(:set_default_flash).with(:error, "There was a problem deleting!")
|
307
|
+
@controller.scope(responses[:destroy_fails].find { |f, p| f == :html }[1]).call
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should redirect back on failure by default for HTML" do
|
311
|
+
@controller.expects(:set_default_redirect).with(:back, :status => :failure)
|
312
|
+
@controller.scope(responses[:destroy_fails].find { |f, p| f == :html }[1]).call
|
313
|
+
end
|
314
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
All the code in this directory comes from the rspec-rails plugin.
|
2
|
+
We've pilfered it as needed to make the make_resourceful specs easier to write.
|
3
|
+
It was made available by its authors under the following license terms:
|
4
|
+
|
5
|
+
(The MIT License)
|
6
|
+
|
7
|
+
====================================================================
|
8
|
+
==== RSpec, RSpec-Rails
|
9
|
+
Copyright (c) 2005-2008 The RSpec Development Team
|
10
|
+
====================================================================
|
11
|
+
==== ARTS
|
12
|
+
Copyright (c) 2006 Kevin Clark, Jake Howerton
|
13
|
+
====================================================================
|
14
|
+
==== ZenTest
|
15
|
+
Copyright (c) 2001-2006 Ryan Davis, Eric Hodel, Zen Spider Software
|
16
|
+
====================================================================
|
17
|
+
==== AssertSelect
|
18
|
+
Copyright (c) 2006 Assaf Arkin
|
19
|
+
====================================================================
|
20
|
+
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
22
|
+
this software and associated documentation files (the "Software"), to deal in
|
23
|
+
the Software without restriction, including without limitation the rights to
|
24
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
25
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
26
|
+
so, subject to the following conditions:
|
27
|
+
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
29
|
+
copies or substantial portions of the Software.
|
30
|
+
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
37
|
+
SOFTWARE.
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Spec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
class RedirectTo #:nodoc:
|
6
|
+
|
7
|
+
def initialize(request, expected)
|
8
|
+
@expected = expected
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(response)
|
13
|
+
@redirected = response.redirect?
|
14
|
+
@actual = response.redirect_url
|
15
|
+
return false unless @redirected
|
16
|
+
if @expected.instance_of? Hash
|
17
|
+
return false unless @actual =~ %r{^\w+://#{@request.host}}
|
18
|
+
return false unless actual_redirect_to_valid_route
|
19
|
+
return actual_hash == expected_hash
|
20
|
+
else
|
21
|
+
return @actual == expected_url
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def actual_hash
|
26
|
+
hash_from_url @actual
|
27
|
+
end
|
28
|
+
|
29
|
+
def expected_hash
|
30
|
+
hash_from_url expected_url
|
31
|
+
end
|
32
|
+
|
33
|
+
def actual_redirect_to_valid_route
|
34
|
+
actual_hash
|
35
|
+
end
|
36
|
+
|
37
|
+
def hash_from_url(url)
|
38
|
+
query_hash(url).merge(path_hash(url)).with_indifferent_access
|
39
|
+
end
|
40
|
+
|
41
|
+
def path_hash(url)
|
42
|
+
path = url.sub(%r{^\w+://#{@request.host}(?::\d+)?}, "").split("?", 2)[0]
|
43
|
+
ActionController::Routing::Routes.recognize_path path
|
44
|
+
end
|
45
|
+
|
46
|
+
def query_hash(url)
|
47
|
+
query = url.split("?", 2)[1] || ""
|
48
|
+
QueryParameterParser.parse_query_parameters(query, @request)
|
49
|
+
end
|
50
|
+
|
51
|
+
def expected_url
|
52
|
+
case @expected
|
53
|
+
when Hash
|
54
|
+
return ActionController::UrlRewriter.new(@request, {}).rewrite(@expected)
|
55
|
+
when :back
|
56
|
+
return @request.env['HTTP_REFERER']
|
57
|
+
when %r{^\w+://.*}
|
58
|
+
return @expected
|
59
|
+
else
|
60
|
+
return "http://#{@request.host}" + (@expected.split('')[0] == '/' ? '' : '/') + @expected
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def failure_message
|
65
|
+
if @redirected
|
66
|
+
return %Q{expected redirect to #{@expected.inspect}, got redirect to #{@actual.inspect}}
|
67
|
+
else
|
68
|
+
return %Q{expected redirect to #{@expected.inspect}, got no redirect}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def negative_failure_message
|
73
|
+
return %Q{expected not to be redirected to #{@expected.inspect}, but was} if @redirected
|
74
|
+
end
|
75
|
+
|
76
|
+
def description
|
77
|
+
"redirect to #{@actual.inspect}"
|
78
|
+
end
|
79
|
+
|
80
|
+
class QueryParameterParser
|
81
|
+
def self.parse_query_parameters(query, request)
|
82
|
+
if defined?(CGIMethods)
|
83
|
+
CGIMethods.parse_query_parameters(query)
|
84
|
+
else
|
85
|
+
request.class.parse_query_parameters(query)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# :call-seq:
|
92
|
+
# response.should redirect_to(url)
|
93
|
+
# response.should redirect_to(:action => action_name)
|
94
|
+
# response.should redirect_to(:controller => controller_name, :action => action_name)
|
95
|
+
# response.should_not redirect_to(url)
|
96
|
+
# response.should_not redirect_to(:action => action_name)
|
97
|
+
# response.should_not redirect_to(:controller => controller_name, :action => action_name)
|
98
|
+
#
|
99
|
+
# Passes if the response is a redirect to the url, action or controller/action.
|
100
|
+
# Useful in controller specs (integration or isolation mode).
|
101
|
+
#
|
102
|
+
# == Examples
|
103
|
+
#
|
104
|
+
# response.should redirect_to("path/to/action")
|
105
|
+
# response.should redirect_to("http://test.host/path/to/action")
|
106
|
+
# response.should redirect_to(:action => 'list')
|
107
|
+
def redirect_to(opts)
|
108
|
+
RedirectTo.new(request, opts)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Spec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
class RenderTemplate #:nodoc:
|
6
|
+
|
7
|
+
def initialize(expected, controller)
|
8
|
+
@controller = controller
|
9
|
+
@expected = expected
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(response)
|
13
|
+
|
14
|
+
if response.respond_to?(:rendered_file)
|
15
|
+
@actual = response.rendered_file
|
16
|
+
else
|
17
|
+
@actual = response.rendered_template.to_s
|
18
|
+
end
|
19
|
+
return false if @actual.blank?
|
20
|
+
given_controller_path, given_file = path_and_file(@actual)
|
21
|
+
expected_controller_path, expected_file = path_and_file(@expected)
|
22
|
+
given_controller_path == expected_controller_path && given_file.match(expected_file)
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message
|
26
|
+
"expected #{@expected.inspect}, got #{@actual.inspect}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def negative_failure_message
|
30
|
+
"expected not to render #{@expected.inspect}, but did"
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
"render template #{@expected.inspect}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def path_and_file(path)
|
39
|
+
parts = path.split('/')
|
40
|
+
file = parts.pop
|
41
|
+
controller = parts.empty? ? current_controller_path : parts.join('/')
|
42
|
+
return controller, file
|
43
|
+
end
|
44
|
+
|
45
|
+
def controller_path_from(path)
|
46
|
+
parts = path.split('/')
|
47
|
+
parts.pop
|
48
|
+
parts.join('/')
|
49
|
+
end
|
50
|
+
|
51
|
+
def current_controller_path
|
52
|
+
@controller.class.to_s.underscore.gsub(/_controller$/,'')
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
# :call-seq:
|
58
|
+
# response.should render_template(path)
|
59
|
+
# response.should_not render_template(path)
|
60
|
+
#
|
61
|
+
# Passes if the specified template is rendered by the response.
|
62
|
+
# Useful in controller specs (integration or isolation mode).
|
63
|
+
#
|
64
|
+
# <code>path</code> can include the controller path or not. It
|
65
|
+
# can also include an optional extension (no extension assumes .rhtml).
|
66
|
+
#
|
67
|
+
# Note that partials must be spelled with the preceding underscore.
|
68
|
+
#
|
69
|
+
# == Examples
|
70
|
+
#
|
71
|
+
# response.should render_template('list')
|
72
|
+
# response.should render_template('same_controller/list')
|
73
|
+
# response.should render_template('other_controller/list')
|
74
|
+
#
|
75
|
+
# #rjs
|
76
|
+
# response.should render_template('list.rjs')
|
77
|
+
# response.should render_template('same_controller/list.rjs')
|
78
|
+
# response.should render_template('other_controller/list.rjs')
|
79
|
+
#
|
80
|
+
# #partials
|
81
|
+
# response.should render_template('_a_partial')
|
82
|
+
# response.should render_template('same_controller/_a_partial')
|
83
|
+
# response.should render_template('other_controller/_a_partial')
|
84
|
+
def render_template(path)
|
85
|
+
RenderTemplate.new(path.to_s, @controller)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Resourceful::Serialize, ".normalize_attributes" do
|
4
|
+
it "should return nil if given nil" do
|
5
|
+
Resourceful::Serialize.normalize_attributes(nil).should be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return a basic hash if given a non-injectable attribute" do
|
9
|
+
Resourceful::Serialize.normalize_attributes(:foo).should == {:foo => nil}
|
10
|
+
Resourceful::Serialize.normalize_attributes(12).should == {12 => nil}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a basic hash with a symbol key if given a string attribute" do
|
14
|
+
Resourceful::Serialize.normalize_attributes("foo").should == {:foo => nil}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should preserve hashes" do
|
18
|
+
Resourceful::Serialize.normalize_attributes({:foo => nil, :bar => nil, :baz => nil}).should ==
|
19
|
+
{:foo => nil, :bar => nil, :baz => nil}
|
20
|
+
Resourceful::Serialize.normalize_attributes({:foo => 3, :bar => 1, :baz => 4}).should ==
|
21
|
+
{:foo => 3, :bar => 1, :baz => 4}
|
22
|
+
Resourceful::Serialize.normalize_attributes({:foo => 3, :bar => 1, :baz => [:foo, :bar]}).should ==
|
23
|
+
{:foo => 3, :bar => 1, :baz => [:foo, :bar]}
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should merge injectable attributes into one big hash" do
|
27
|
+
Resourceful::Serialize.normalize_attributes([:foo, :bar, :baz]).should ==
|
28
|
+
{:foo => nil, :bar => nil, :baz => nil}
|
29
|
+
Resourceful::Serialize.normalize_attributes([:foo, :bar, {:baz => nil},
|
30
|
+
:boom, {:bop => nil, :blat => nil}]).should ==
|
31
|
+
{:foo => nil, :bar => nil, :baz => nil, :boom => nil, :bop => nil, :blat => nil}
|
32
|
+
Resourceful::Serialize.normalize_attributes([:foo, :bar, {:baz => 12},
|
33
|
+
:boom, {:bop => "foo", :blat => [:fee, :fi, :fo]}]).should ==
|
34
|
+
{:foo => nil, :bar => nil, :baz => 12, :boom => nil, :bop => "foo", :blat => [:fee, :fi, :fo]}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Array, " of non-serializable objects" do
|
39
|
+
before :each do
|
40
|
+
@array = [1, 2, 3, 4, "foo"]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return itself for #to_serializable" do
|
44
|
+
@array.to_serializable(nil).should == @array
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise an error for #serialize" do
|
48
|
+
lambda { @array.serialize(:yaml, :attributes => [:foo]) }.should raise_error("Not all elements respond to to_serializable")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Array, " of serializable objects" do
|
53
|
+
before :each do
|
54
|
+
@cat = stub_model("Cat")
|
55
|
+
@dog = stub_model("Dog")
|
56
|
+
@array = %w{brown yellow green}.zip(%w{rex rover fido}).
|
57
|
+
map { |c, d| @cat.new(:fur => c, :friend => @dog.new(:name => d)) }
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return an array of serializable hashes for #to_serializable" do
|
61
|
+
@array.to_serializable([:fur]).should == [{'fur' => 'brown'}, {'fur' => 'yellow'}, {'fur' => 'green'}]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should follow deep attributes for #to_serializable" do
|
65
|
+
@array.to_serializable([:fur, {:friend => :name}]).should ==
|
66
|
+
[{'fur' => 'brown', 'friend' => {'name' => 'rex'}},
|
67
|
+
{'fur' => 'yellow', 'friend' => {'name' => 'rover'}},
|
68
|
+
{'fur' => 'green', 'friend' => {'name' => 'fido'}}]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise an error if #serialize is called without the :attributes option" do
|
72
|
+
lambda { @array.serialize(:yaml, {}) }.should raise_error("Must specify :attributes option")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should serialize to a hash with a pluralized root for #serialize" do
|
76
|
+
YAML.load(@array.serialize(:yaml, :attributes => [:fur, {:friend => :name}])).should ==
|
77
|
+
{"cats" => [{'fur' => 'brown', 'friend' => {'name' => 'rex'}},
|
78
|
+
{'fur' => 'yellow', 'friend' => {'name' => 'rover'}},
|
79
|
+
{'fur' => 'green', 'friend' => {'name' => 'fido'}}]}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should serialize to an XML document with a pluralized root for #serialize(:xml, ...)" do
|
83
|
+
doc = REXML::Document.new(@array.serialize(:xml, :attributes => [:fur, {:friend => :name}]),
|
84
|
+
:ignore_whitespace_nodes => :all)
|
85
|
+
doc.root.name.should == "cats"
|
86
|
+
cats = doc.get_elements('/cats/cat')
|
87
|
+
cats.size.should == 3
|
88
|
+
cats.zip(%w{brown yellow green}, %w{rex rover fido}) do |cat, fur, dog|
|
89
|
+
cat.children.find { |e| e.name == "fur" }.text.should == fur
|
90
|
+
cat.children.find { |e| e.name == "friend" }.children[0].text.should == dog
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe ActiveRecord::Base, " with a few attributes and an association" do
|
96
|
+
before :each do
|
97
|
+
@person = stub_model("Person")
|
98
|
+
@party_hat = stub_model("PartyHat")
|
99
|
+
@model = @person.new(:name => "joe", :eye_color => "blue", :hairs => 567,
|
100
|
+
:party_hat => @party_hat.new(:color => 'blue', :size => 12, :pattern => 'stripey'))
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should raise an error if #to_serializable is called without attributes" do
|
104
|
+
lambda { @model.to_serializable(nil) }.should raise_error("Must specify attributes for #<Person>.to_serializable")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return an attributes hash for #to_serializable" do
|
108
|
+
@model.to_serializable([:name, :hairs, {:party_hat => [:color, :size]}]).should ==
|
109
|
+
{'name' => 'joe', 'hairs' => 567, 'party_hat' => {
|
110
|
+
'color' => 'blue', 'size' => 12
|
111
|
+
}}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should raise an error if #serialize is called without the :attributes option" do
|
115
|
+
lambda { @model.serialize(:yaml, {}) }.should raise_error("Must specify :attributes option")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should serialize to a hash for #serialize" do
|
119
|
+
YAML.load(@model.serialize(:yaml, :attributes => [:hairs, :eye_color, {:party_hat => :size}])).should ==
|
120
|
+
{"person" => {'hairs' => 567, 'eye_color' => 'blue', 'party_hat' => {'size' => 12}}}
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should serialize to an XML document for #serialize(:xml, ...)" do
|
124
|
+
doc = REXML::Document.new(@model.serialize(:xml, :attributes => [:name, :eye_color, {:party_hat => :pattern}]),
|
125
|
+
:ignore_whitespace_nodes => :all)
|
126
|
+
doc.root.name.should == "person"
|
127
|
+
doc.root.children.find { |e| e.name == "name" }.text.should == "joe"
|
128
|
+
doc.root.children.find { |e| e.name == "eye-color" }.text.should == "blue"
|
129
|
+
|
130
|
+
hat = doc.root.children.find { |e| e.name == "party-hat" }
|
131
|
+
hat.children.find { |e| e.name == "pattern" }.text.should == "stripey"
|
132
|
+
end
|
133
|
+
end
|