wrest 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/README.rdoc +16 -10
- data/Rakefile +361 -123
- data/VERSION.yml +2 -2
- data/examples/delicious.rb +17 -7
- data/examples/facebook.rb +101 -0
- data/examples/keep_alive.rb +37 -0
- data/examples/twitter.rb +3 -3
- data/examples/twitter_public_timeline.rb +11 -4
- data/examples/wow_realm_status.rb +8 -2
- data/{spec/functional/sample_rails_app/public/favicon.ico → init.rb} +0 -0
- data/lib/wrest/components/{attributes_container → container}/alias_accessors.rb +4 -4
- data/lib/wrest/components/{attributes_container → container}/typecaster.rb +1 -1
- data/lib/wrest/components/{attributes_container.rb → container.rb} +46 -16
- data/lib/wrest/components/mutators.rb +4 -4
- data/lib/wrest/components/translators/json.rb +2 -2
- data/lib/wrest/components/translators/xml.rb +3 -2
- data/lib/wrest/components/translators.rb +3 -3
- data/lib/wrest/components.rb +3 -3
- data/lib/wrest/core_ext/hash.rb +1 -1
- data/lib/wrest/core_ext/string.rb +1 -1
- data/lib/wrest/curl/delete.rb +23 -0
- data/lib/wrest/curl/get.rb +23 -0
- data/lib/wrest/curl/options.rb +16 -0
- data/lib/wrest/curl/post.rb +23 -0
- data/lib/wrest/curl/put.rb +23 -0
- data/lib/wrest/curl/request.rb +95 -0
- data/lib/wrest/curl/response.rb +63 -0
- data/lib/wrest/curl/session.rb +57 -0
- data/lib/wrest/curl.rb +49 -0
- data/lib/wrest/exceptions.rb +16 -1
- data/lib/wrest/http_shared/headers.rb +350 -0
- data/lib/wrest/http_shared/standard_headers.rb +21 -0
- data/lib/wrest/http_shared/standard_tokens.rb +18 -0
- data/lib/wrest/http_shared.rb +24 -0
- data/lib/wrest/native/connection_factory.rb +23 -0
- data/lib/wrest/{http → native}/delete.rb +1 -1
- data/lib/wrest/{http → native}/get.rb +1 -1
- data/lib/wrest/{http → native}/options.rb +1 -1
- data/lib/wrest/{http → native}/post.rb +1 -1
- data/lib/wrest/{http → native}/put.rb +1 -1
- data/lib/wrest/{http → native}/redirection.rb +4 -1
- data/lib/wrest/{http → native}/request.rb +32 -20
- data/lib/wrest/{http → native}/response.rb +12 -4
- data/lib/wrest/native/session.rb +57 -0
- data/lib/wrest/native.rb +32 -0
- data/lib/wrest/resource/base.rb +1 -1
- data/lib/wrest/resource.rb +1 -1
- data/lib/wrest/test/request_patches.rb +5 -0
- data/lib/wrest/test.rb +1 -0
- data/lib/wrest/uri.rb +31 -3
- data/lib/wrest/version.rb +2 -2
- data/lib/wrest.rb +52 -16
- data/spec/unit/spec_helper.rb +12 -3
- data/spec/unit/wrest/components/attributes_container/alias_accessors_spec.rb +2 -2
- data/spec/unit/wrest/components/attributes_container/typecaster_spec.rb +6 -6
- data/spec/unit/wrest/components/attributes_container_spec.rb +44 -12
- data/spec/unit/wrest/components/translators/xml_spec.rb +7 -3
- data/spec/unit/wrest/curl/request_spec.rb +19 -0
- data/spec/unit/wrest/curl/response_spec.rb +16 -0
- data/spec/unit/wrest/http/response_spec.rb +17 -38
- data/spec/unit/wrest/{http → native}/redirection_spec.rb +5 -5
- data/spec/unit/wrest/{http → native}/request_spec.rb +15 -14
- data/spec/unit/wrest/native/response_spec.rb +72 -0
- data/spec/unit/wrest/native/session_spec.rb +74 -0
- data/spec/unit/wrest/resource/base_spec.rb +2 -2
- data/spec/unit/wrest/uri_spec.rb +51 -11
- data/wrest.gemspec +164 -0
- metadata +51 -165
- data/lib/wrest/http.rb +0 -25
- data/spec/functional/sample_rails_app/README +0 -3
- data/spec/functional/sample_rails_app/Rakefile +0 -10
- data/spec/functional/sample_rails_app/app/controllers/application_controller.rb +0 -10
- data/spec/functional/sample_rails_app/app/controllers/lead_bottles_controller.rb +0 -7
- data/spec/functional/sample_rails_app/app/helpers/application_helper.rb +0 -3
- data/spec/functional/sample_rails_app/app/models/bottle.rb +0 -3
- data/spec/functional/sample_rails_app/app/models/glass_bottle.rb +0 -3
- data/spec/functional/sample_rails_app/app/models/lead_bottle.rb +0 -3
- data/spec/functional/sample_rails_app/config/boot.rb +0 -110
- data/spec/functional/sample_rails_app/config/database.yml +0 -16
- data/spec/functional/sample_rails_app/config/environment.rb +0 -42
- data/spec/functional/sample_rails_app/config/environments/development.rb +0 -17
- data/spec/functional/sample_rails_app/config/environments/production.rb +0 -28
- data/spec/functional/sample_rails_app/config/environments/test.rb +0 -28
- data/spec/functional/sample_rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/functional/sample_rails_app/config/initializers/inflections.rb +0 -10
- data/spec/functional/sample_rails_app/config/initializers/mime_types.rb +0 -5
- data/spec/functional/sample_rails_app/config/initializers/new_rails_defaults.rb +0 -19
- data/spec/functional/sample_rails_app/config/initializers/session_store.rb +0 -15
- data/spec/functional/sample_rails_app/config/locales/en.yml +0 -5
- data/spec/functional/sample_rails_app/config/routes.rb +0 -3
- data/spec/functional/sample_rails_app/db/development.sqlite3 +0 -0
- data/spec/functional/sample_rails_app/db/migrate/20090319115628_create_bottle.rb +0 -13
- data/spec/functional/sample_rails_app/db/schema.rb +0 -20
- data/spec/functional/sample_rails_app/db/test.sqlite3 +0 -0
- data/spec/functional/sample_rails_app/log/development.log +0 -1
- data/spec/functional/sample_rails_app/public/404.html +0 -30
- data/spec/functional/sample_rails_app/public/422.html +0 -30
- data/spec/functional/sample_rails_app/public/500.html +0 -30
- data/spec/functional/sample_rails_app/public/images/rails.png +0 -0
- data/spec/functional/sample_rails_app/public/index.html +0 -275
- data/spec/functional/sample_rails_app/public/robots.txt +0 -5
- data/spec/functional/sample_rails_app/script/about +0 -4
- data/spec/functional/sample_rails_app/script/autospec +0 -6
- data/spec/functional/sample_rails_app/script/console +0 -3
- data/spec/functional/sample_rails_app/script/dbconsole +0 -3
- data/spec/functional/sample_rails_app/script/destroy +0 -3
- data/spec/functional/sample_rails_app/script/generate +0 -3
- data/spec/functional/sample_rails_app/script/performance/benchmarker +0 -3
- data/spec/functional/sample_rails_app/script/performance/profiler +0 -3
- data/spec/functional/sample_rails_app/script/plugin +0 -3
- data/spec/functional/sample_rails_app/script/runner +0 -3
- data/spec/functional/sample_rails_app/script/server +0 -3
- data/spec/functional/sample_rails_app/script/spec +0 -10
- data/spec/functional/sample_rails_app/script/spec_server +0 -9
- data/spec/functional/sample_rails_app/test/performance/browsing_test.rb +0 -9
- data/spec/functional/sample_rails_app/test/test_helper.rb +0 -38
- data/spec/functional/sample_rails_app/tmtags +0 -2559
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/MIT-LICENSE +0 -20
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/README.rdoc +0 -100
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/Rakefile +0 -18
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/init.rb +0 -5
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/install.rb +0 -1
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/base.rb +0 -140
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/controllers/resources.rb +0 -16
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/controllers/resources_controller.rb +0 -26
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/controllers/routes_controller.rb +0 -16
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/core_extensions/api.rb +0 -26
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/core_extensions/exception.rb +0 -23
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/core_extensions/from_json.rb +0 -15
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/dispatch.rb +0 -235
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/models/resourced_route.rb +0 -84
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/query.rb +0 -337
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render/html.rb +0 -50
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render/json.rb +0 -75
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render/xml.rb +0 -65
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render.rb +0 -63
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/retrieve.rb +0 -74
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/version.rb +0 -9
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full.rb +0 -14
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/base_spec.rb +0 -88
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/controllers/resources_spec.rb +0 -29
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/dispatch_spec.rb +0 -262
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/models/resourced_route_spec.rb +0 -62
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/query/parameter_spec.rb +0 -57
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/query_spec.rb +0 -462
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render/html_spec.rb +0 -4
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render/json_spec.rb +0 -107
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render/xml_spec.rb +0 -98
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render_spec.rb +0 -5
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/retrieve_spec.rb +0 -173
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/spec_helper.rb +0 -98
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/uninstall.rb +0 -1
- data/spec/functional/spec_helper.rb +0 -0
data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/query_spec.rb
DELETED
@@ -1,462 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe "ResourceFull::Query", :type => :controller do
|
4
|
-
controller_name "resource_full_mock_users"
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
ResourceFullMockUser.delete_all
|
8
|
-
@users = [
|
9
|
-
ResourceFullMockUser.create!(:resource_full_mock_employer_id => 1, :income => 70_000, :first_name => "guybrush"),
|
10
|
-
ResourceFullMockUser.create!(:resource_full_mock_employer_id => 1, :income => 30_000, :first_name => "toothbrush"),
|
11
|
-
ResourceFullMockUser.create!(:resource_full_mock_employer_id => 2, :income => 70_000, :first_name => "guthrie"),
|
12
|
-
]
|
13
|
-
@guybrush, @toothbrush, @guthrie = @users
|
14
|
-
end
|
15
|
-
attr_reader :users
|
16
|
-
|
17
|
-
before :each do
|
18
|
-
ResourceFullMockUsersController.queryable_params = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it "isn't queryable on any parameters by default" do
|
22
|
-
controller.class.queryable_params.should be_empty
|
23
|
-
end
|
24
|
-
|
25
|
-
it "allows you to specify queryable parameters" do
|
26
|
-
controller.class.queryable_with :resource_full_mock_employer_id, :income
|
27
|
-
controller.class.queryable_params.collect(&:name).should include(:resource_full_mock_employer_id, :income)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "retrieves objects based on a queried condition" do
|
31
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
32
|
-
get :index, :resource_full_mock_employer_id => 1
|
33
|
-
assigns(:resource_full_mock_users).should include(users[0], users[1])
|
34
|
-
assigns(:resource_full_mock_users).should_not include(users[2])
|
35
|
-
end
|
36
|
-
|
37
|
-
it "retrieves no objects if the queried condition is not matched" do
|
38
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
39
|
-
get :index, :resource_full_mock_employer_id => 3
|
40
|
-
assigns(:resource_full_mock_users).should be_empty
|
41
|
-
end
|
42
|
-
|
43
|
-
it "queries on the intersection of multiple conditions" do
|
44
|
-
controller.class.queryable_with :resource_full_mock_employer_id, :income
|
45
|
-
get :index, :resource_full_mock_employer_id => 1, :income => 70_000
|
46
|
-
assigns(:resource_full_mock_users).should == [ users[0] ]
|
47
|
-
end
|
48
|
-
|
49
|
-
it "queries multiple values in a comma-separated list" do
|
50
|
-
controller.class.queryable_with :resource_full_mock_employer_id, :income
|
51
|
-
get :index, :resource_full_mock_employer_id => "1,2"
|
52
|
-
assigns(:resource_full_mock_users).should include(*users)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "queries multiple values in standard request parameter list format" do
|
56
|
-
controller.class.queryable_with :resource_full_mock_employer_id, :income
|
57
|
-
get :index, :resource_full_mock_employer_id => [ '1', '2' ]
|
58
|
-
assigns(:resource_full_mock_users).should include(*users)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "retrieves objects given pluralized forms of queryable parameters" do
|
62
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
63
|
-
get :index, :resource_full_mock_employer_ids => "1,2"
|
64
|
-
assigns(:resource_full_mock_users).should include(*users)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "uses LIKE clauses to query if the fuzzy option is specified" do
|
68
|
-
controller.class.queryable_with :first_name, :fuzzy => true
|
69
|
-
get :index, :first_name => "gu"
|
70
|
-
assigns(:resource_full_mock_users).should include(users[0], users[2])
|
71
|
-
assigns(:resource_full_mock_users).should_not include(users[1])
|
72
|
-
end
|
73
|
-
|
74
|
-
it "allows a queryable parameter to map to a different column" do
|
75
|
-
controller.class.queryable_with :address, :column => :resource_full_mock_employer_id
|
76
|
-
get :index, :address => 1
|
77
|
-
assigns(:resource_full_mock_users).should include(users[0], users[1])
|
78
|
-
assigns(:resource_full_mock_users).should_not include(users[2])
|
79
|
-
end
|
80
|
-
|
81
|
-
it "appends to rather than replaces queryable values" do
|
82
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
83
|
-
controller.class.queryable_with :income
|
84
|
-
|
85
|
-
get :index, :resource_full_mock_employer_id => 1, :income => 70_000
|
86
|
-
assigns(:resource_full_mock_users).should include(users[0])
|
87
|
-
assigns(:resource_full_mock_users).should_not include(users[1], users[2])
|
88
|
-
end
|
89
|
-
|
90
|
-
it "counts all objects if there are no parameters" do
|
91
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
92
|
-
get :count
|
93
|
-
Hash.from_xml(response.body)['count'].to_i.should == 3
|
94
|
-
end
|
95
|
-
|
96
|
-
it "counts the requested objects if there are paramters" do
|
97
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
98
|
-
get :count, :resource_full_mock_employer_id => 1
|
99
|
-
Hash.from_xml(response.body)['count'].to_i.should == 2
|
100
|
-
end
|
101
|
-
|
102
|
-
it "counts no objects if there are none with the requested parameters" do
|
103
|
-
controller.class.queryable_with :resource_full_mock_employer_id
|
104
|
-
get :count, :resource_full_mock_employer_id => 15
|
105
|
-
Hash.from_xml(response.body)['count'].to_i.should == 0
|
106
|
-
end
|
107
|
-
|
108
|
-
it "negates a single queried value" do
|
109
|
-
ResourceFullMockUsersController.queryable_with :not_resource_full_mock_employer_id, :negated => true, :column => :resource_full_mock_employer_id
|
110
|
-
|
111
|
-
get :index, :not_resource_full_mock_employer_id => 2
|
112
|
-
assigns(:resource_full_mock_users).should include(users[0], users[1])
|
113
|
-
assigns(:resource_full_mock_users).should_not include(users[2])
|
114
|
-
end
|
115
|
-
|
116
|
-
it "negates multiple queried values" do
|
117
|
-
ResourceFullMockUsersController.queryable_with :not_resource_full_mock_employer_id, :negated => true, :column => :resource_full_mock_employer_id
|
118
|
-
|
119
|
-
get :index, :not_resource_full_mock_employer_id => [1, 2]
|
120
|
-
assigns(:resource_full_mock_users).should be_empty
|
121
|
-
end
|
122
|
-
|
123
|
-
it "negates a fuzzy string value" do
|
124
|
-
ResourceFullMockUsersController.queryable_with :not_first_name, :negated => true, :column => :first_name, :fuzzy => true
|
125
|
-
|
126
|
-
get :index, :not_first_name => "brush"
|
127
|
-
assigns(:resource_full_mock_users).should include(@guthrie)
|
128
|
-
assigns(:resource_full_mock_users).should_not include(@guybrush, @toothbrush)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "negates a queried value with a column defined by a proc" do
|
132
|
-
ResourceFullMockUsersController.queryable_with :not_resource_full_mock_employer_id, :negated => true, :column => lambda {|id| :resource_full_mock_employer_id}
|
133
|
-
|
134
|
-
get :index, :not_resource_full_mock_employer_id => 2
|
135
|
-
assigns(:resource_full_mock_users).should include(users[0], users[1])
|
136
|
-
assigns(:resource_full_mock_users).should_not include(users[2])
|
137
|
-
end
|
138
|
-
|
139
|
-
it "negates a queried value and returns all records for which the value is null" do
|
140
|
-
ResourceFullMockUsersController.queryable_with :not_resource_full_mock_employer_id, :negated => true, :column => :resource_full_mock_employer_id
|
141
|
-
null_user = ResourceFullMockUser.create!
|
142
|
-
|
143
|
-
get :index, :not_resource_full_mock_employer_id => [1, 2]
|
144
|
-
assigns(:resource_full_mock_users).should == [ null_user ]
|
145
|
-
end
|
146
|
-
|
147
|
-
it "allows you to specify a default value, which it uses if there is no explicit value given for that parameter" do
|
148
|
-
ResourceFullMockUsersController.queryable_with :first_name, :default => "guybrush"
|
149
|
-
|
150
|
-
get :index
|
151
|
-
assigns(:resource_full_mock_users).should == [ @guybrush ]
|
152
|
-
end
|
153
|
-
|
154
|
-
it "allows you to override the default value if an explicit value is specified" do
|
155
|
-
ResourceFullMockUsersController.queryable_with :first_name, :default => "guybrush"
|
156
|
-
|
157
|
-
get :index, :first_name => "toothbrush"
|
158
|
-
assigns(:resource_full_mock_users).should == [ @toothbrush ]
|
159
|
-
end
|
160
|
-
|
161
|
-
describe "with multiple columns" do
|
162
|
-
controller_name "resource_full_mock_users"
|
163
|
-
|
164
|
-
before :all do
|
165
|
-
ResourceFullMockUser.delete_all
|
166
|
-
@users = [
|
167
|
-
ResourceFullMockUser.create!(:first_name => "guybrush", :last_name => "threepwood"),
|
168
|
-
ResourceFullMockUser.create!(:first_name => "herman", :last_name => "guybrush"),
|
169
|
-
ResourceFullMockUser.create!(:first_name => "ghost_pirate", :last_name => "le_chuck")
|
170
|
-
]
|
171
|
-
end
|
172
|
-
attr_reader :users
|
173
|
-
|
174
|
-
before :each do
|
175
|
-
ResourceFullMockUsersController.queryable_params = nil
|
176
|
-
end
|
177
|
-
|
178
|
-
it "allows a queryable parameter to map to multiple columns" do
|
179
|
-
controller.class.queryable_with :name, :columns => [:first_name, :last_name]
|
180
|
-
get :index, :name => "guybrush"
|
181
|
-
assigns(:resource_full_mock_users).should include(users[0], users[1])
|
182
|
-
assigns(:resource_full_mock_users).should_not include(users[2])
|
183
|
-
end
|
184
|
-
|
185
|
-
it "queries fuzzy values across multiple columns" do
|
186
|
-
controller.class.queryable_with :name, :columns => [:first_name, :last_name], :fuzzy => true
|
187
|
-
get :index, :name => "gu"
|
188
|
-
assigns(:resource_full_mock_users).should include(users[0], users[1])
|
189
|
-
assigns(:resource_full_mock_users).should_not include(users[2])
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe "with joins" do
|
194
|
-
controller_name "resource_full_mock_addresses"
|
195
|
-
|
196
|
-
before :each do
|
197
|
-
ResourceFullMockUser.delete_all
|
198
|
-
ResourceFullMockAddress.delete_all
|
199
|
-
|
200
|
-
@user = ResourceFullMockUser.create! :email => "gthreepwood@melee.gov"
|
201
|
-
@valid_addresses = [
|
202
|
-
@user.resource_full_mock_addresses.create!,
|
203
|
-
@user.resource_full_mock_addresses.create!
|
204
|
-
]
|
205
|
-
|
206
|
-
invalid_user = ResourceFullMockUser.create! :email => "blah@blah.com"
|
207
|
-
@invalid_address = invalid_user.resource_full_mock_addresses.create!
|
208
|
-
|
209
|
-
ResourceFullMockUsersController.resource_identifier = :id
|
210
|
-
ResourceFullMockAddressesController.clear_queryable_params!
|
211
|
-
end
|
212
|
-
attr_reader :user, :valid_addresses, :invalid_address
|
213
|
-
|
214
|
-
it "filters addresses by the appropriate column and join if a :from relationship is defined" do
|
215
|
-
ResourceFullMockAddressesController.queryable_with :email, :from => :resource_full_mock_user
|
216
|
-
|
217
|
-
get :index, :resource_full_mock_user_id => 'foo', :email => user.email
|
218
|
-
assigns(:resource_full_mock_addresses).should include(*valid_addresses)
|
219
|
-
assigns(:resource_full_mock_addresses).should_not include(invalid_address)
|
220
|
-
end
|
221
|
-
|
222
|
-
it "filters addresses by the User resource identifier if a :from is specified along with :resource_identifier" do
|
223
|
-
ResourceFullMockUsersController.resource_identifier = :email
|
224
|
-
ResourceFullMockAddressesController.queryable_with :resource_full_mock_user_id, :from => :resource_full_mock_user, :resource_identifier => true
|
225
|
-
|
226
|
-
get :index, :resource_full_mock_user_id => user.email
|
227
|
-
assigns(:resource_full_mock_addresses).should include(*valid_addresses)
|
228
|
-
assigns(:resource_full_mock_addresses).should_not include(invalid_address)
|
229
|
-
end
|
230
|
-
|
231
|
-
it "filters addresses by the User resource identifier if a :from is specified along with :resource_identifier and the resource identifer is a Proc" do
|
232
|
-
ResourceFullMockUsersController.identified_by :email, :unless => :id_numeric
|
233
|
-
ResourceFullMockAddressesController.queryable_with :resource_full_mock_user_id, :from => :resource_full_mock_user, :resource_identifier => true
|
234
|
-
|
235
|
-
get :index, :resource_full_mock_user_id => user.id
|
236
|
-
assigns(:resource_full_mock_addresses).should include(*valid_addresses)
|
237
|
-
assigns(:resource_full_mock_addresses).should_not include(invalid_address)
|
238
|
-
end
|
239
|
-
|
240
|
-
it "filters addresses by the Employer resource by specifying a table name and ensuring that the intermediate User resource is included in the query" do
|
241
|
-
employer = ResourceFullMockEmployer.create! :name => "Melee Island Dept. of Piracy"
|
242
|
-
@user.update_attributes :resource_full_mock_employer => employer
|
243
|
-
ResourceFullMockEmployer.create! :name => "Kingdom of Phatt Island"
|
244
|
-
|
245
|
-
ResourceFullMockAddressesController.queryable_with :resource_full_mock_employer_name,
|
246
|
-
:from => { :resource_full_mock_user => :resource_full_mock_employer },
|
247
|
-
:table => 'resource_full_mock_employers',
|
248
|
-
:column => :name,
|
249
|
-
:fuzzy => true
|
250
|
-
|
251
|
-
get :index, :resource_full_mock_employer_name => "Melee"
|
252
|
-
assigns(:resource_full_mock_addresses).should include(*valid_addresses)
|
253
|
-
assigns(:resource_full_mock_addresses).should_not include(invalid_address)
|
254
|
-
end
|
255
|
-
|
256
|
-
# TODO This is perhaps not the best place for this test.
|
257
|
-
it "filters addresses by the User resource identifer if a controller is said to nest within another controller" do
|
258
|
-
ResourceFullMockUsersController.resource_identifier = :email
|
259
|
-
ResourceFullMockAddressesController.nests_within(:resource_full_mock_user)
|
260
|
-
|
261
|
-
get :index, :resource_full_mock_user_id => user.email
|
262
|
-
assigns(:resource_full_mock_addresses).should include(*valid_addresses)
|
263
|
-
assigns(:resource_full_mock_addresses).should_not include(invalid_address)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
describe "with subclasses" do
|
268
|
-
controller_name "resource_full_sub_mocks"
|
269
|
-
before :each do
|
270
|
-
ResourceFullMocksController.queryable_params = nil
|
271
|
-
ResourceFullSubMocksController.queryable_params = nil
|
272
|
-
end
|
273
|
-
|
274
|
-
it "allows subclasses to add to the list of queryable parameters" do
|
275
|
-
ResourceFullMocksController.queryable_with :foo
|
276
|
-
ResourceFullSubMocksController.queryable_with :bar
|
277
|
-
ResourceFullSubMocksController.should be_queryable_with(:foo, :bar)
|
278
|
-
end
|
279
|
-
|
280
|
-
it "doesn't alter the queryable parameters of a superclass when a subclass" do
|
281
|
-
ResourceFullMocksController.queryable_with :foo
|
282
|
-
ResourceFullSubMocksController.queryable_with :bar
|
283
|
-
ResourceFullMocksController.should_not be_queryable_with(:bar)
|
284
|
-
end
|
285
|
-
|
286
|
-
it "uses the model and table name of the subclass rather than the superclass when querying" do
|
287
|
-
ResourceFullMocksController.queryable_with :first_name
|
288
|
-
ResourceFullSubMocksController.exposes :resource_full_mock_users
|
289
|
-
ResourceFullMockUser.create! :first_name => "guybrush"
|
290
|
-
ResourceFullMock.expects(:find).never
|
291
|
-
get :index, :format => 'xml', :first_name => 'guybrush'
|
292
|
-
response.body.should have_tag("resource-full-mock-user") { with_tag("first-name", "guybrush") }
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
describe "with named scope" do
|
297
|
-
controller_name "resource_full_mock_users"
|
298
|
-
|
299
|
-
it "filters parameter values using the given named scope method if no parameters are given" do
|
300
|
-
ResourceFullMockUsersController.queryable_with :born_today, :scope => :born_today
|
301
|
-
ResourceFullMockUser.named_scope :born_today, :conditions => { :birthdate => Date.today }
|
302
|
-
|
303
|
-
real_user = ResourceFullMockUser.create! :birthdate => Date.today
|
304
|
-
noise_user = ResourceFullMockUser.create! :birthdate => Date.yesterday
|
305
|
-
|
306
|
-
get :index, :format => 'xml', :born_today => true
|
307
|
-
|
308
|
-
assigns(:resource_full_mock_users).should == [ real_user ]
|
309
|
-
end
|
310
|
-
|
311
|
-
it "filters parameter values using the given named scope proc if no parameters are given" do
|
312
|
-
ResourceFullMockUsersController.queryable_with :born_today, :scope => lambda { {:conditions => { :birthdate => Date.today } } }
|
313
|
-
|
314
|
-
real_user = ResourceFullMockUser.create! :birthdate => Date.today
|
315
|
-
noise_user = ResourceFullMockUser.create! :birthdate => Date.yesterday
|
316
|
-
|
317
|
-
get :index, :format => 'xml', :born_today => true
|
318
|
-
|
319
|
-
assigns(:resource_full_mock_users).should == [ real_user ]
|
320
|
-
end
|
321
|
-
|
322
|
-
it "filters parameter values using the given named scope hash if no parameters are given" do
|
323
|
-
ResourceFullMockUsersController.queryable_with :born_today, :scope => { :conditions => { :birthdate => Date.today } }
|
324
|
-
|
325
|
-
real_user = ResourceFullMockUser.create! :birthdate => Date.today
|
326
|
-
noise_user = ResourceFullMockUser.create! :birthdate => Date.yesterday
|
327
|
-
|
328
|
-
get :index, :format => 'xml', :born_today => true
|
329
|
-
|
330
|
-
assigns(:resource_full_mock_users).should == [ real_user ]
|
331
|
-
end
|
332
|
-
|
333
|
-
it "filters parameter values using the given named scope method if a parameter is given" do
|
334
|
-
ResourceFullMockUser.named_scope :named, lambda { |name| { :conditions => { :first_name => name } } }
|
335
|
-
ResourceFullMockUsersController.queryable_with :named, :scope => :named
|
336
|
-
|
337
|
-
real_user = ResourceFullMockUser.create! :first_name => "Guybrush"
|
338
|
-
noise_user = ResourceFullMockUser.create! :first_name => "Toothbrush"
|
339
|
-
|
340
|
-
get :index, :format => 'xml', :named => "Guybrush"
|
341
|
-
|
342
|
-
assigns(:resource_full_mock_users).should == ResourceFullMockUser.named("Guybrush")
|
343
|
-
end
|
344
|
-
|
345
|
-
it "filters parameter values fuzzily using the given named scope method if a parameter is given and fuzzy is specified" do
|
346
|
-
ResourceFullMockUser.named_scope :named, lambda { |name| { :conditions => { :first_name => name } } }
|
347
|
-
ResourceFullMockUsersController.queryable_with :named, :scope => :named, :fuzzy => true
|
348
|
-
|
349
|
-
real_user = ResourceFullMockUser.create! :first_name => "Guybrush"
|
350
|
-
noise_user = ResourceFullMockUser.create! :first_name => "Toothbrush"
|
351
|
-
|
352
|
-
get :index, :format => 'xml', :named => "brush"
|
353
|
-
|
354
|
-
assigns(:resource_full_mock_users).should == ResourceFullMockUser.named("%brush%")
|
355
|
-
end
|
356
|
-
|
357
|
-
it "filters parameter values using multiple named scopes by chaining them together" do
|
358
|
-
ResourceFullMockUsersController.queryable_with :born_today, :scope => :born_today
|
359
|
-
ResourceFullMockUsersController.queryable_with :named_guybrush, :scope => :named_guybrush
|
360
|
-
|
361
|
-
ResourceFullMockUser.named_scope :born_today, :conditions => { :birthdate => Date.today }
|
362
|
-
ResourceFullMockUser.named_scope :named_guybrush, :conditions => { :first_name => "Guybrush" }
|
363
|
-
|
364
|
-
real_user = ResourceFullMockUser.create! :birthdate => Date.today, :first_name => "Guybrush"
|
365
|
-
yesterday_user = ResourceFullMockUser.create! :birthdate => Date.yesterday, :first_name => "Guybrush"
|
366
|
-
toothbrush_user = ResourceFullMockUser.create! :birthdate => Date.today, :first_name => "Toothbrush"
|
367
|
-
|
368
|
-
get :index, :format => 'xml', :born_today => true, :named_guybrush => true
|
369
|
-
|
370
|
-
assigns(:resource_full_mock_users).should == ResourceFullMockUser.born_today.named_guybrush
|
371
|
-
end
|
372
|
-
|
373
|
-
# I know this works experimentally but have yet to write the test.
|
374
|
-
it "combines named scope filters with standard queryable_with parameter filters"
|
375
|
-
end
|
376
|
-
|
377
|
-
describe "with nils" do
|
378
|
-
controller_name "resource_full_mock_users"
|
379
|
-
|
380
|
-
before :each do
|
381
|
-
ResourceFullMockUser.delete_all
|
382
|
-
end
|
383
|
-
|
384
|
-
it "finds records when an allow_nil queryable parameter is blank" do
|
385
|
-
ResourceFullMockUsersController.queryable_with :resource_full_mock_employer_id, :allow_nil => true
|
386
|
-
real_user = ResourceFullMockUser.create! :first_name => "brian", :resource_full_mock_employer_id => nil
|
387
|
-
noise_user = ResourceFullMockUser.create! :first_name => "brian", :resource_full_mock_employer_id => 13
|
388
|
-
|
389
|
-
get :index, :resource_full_mock_employer_id => nil
|
390
|
-
assigns(:resource_full_mock_users).should == [ real_user ]
|
391
|
-
end
|
392
|
-
|
393
|
-
it "finds records when an allow_nil queryable parameter contains a value" do
|
394
|
-
ResourceFullMockUsersController.queryable_with :resource_full_mock_employer_id, :allow_nil => true
|
395
|
-
real_user = ResourceFullMockUser.create! :first_name => "brian", :resource_full_mock_employer_id => 13
|
396
|
-
nil_user = ResourceFullMockUser.create! :first_name => "brian", :resource_full_mock_employer_id => nil
|
397
|
-
wrong_user = ResourceFullMockUser.create! :first_name => "brian", :resource_full_mock_employer_id => 16
|
398
|
-
|
399
|
-
get :index, :resource_full_mock_employer_id => 13
|
400
|
-
assigns(:resource_full_mock_users).should == [ real_user ]
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
describe "with sorting" do
|
405
|
-
controller_name "resource_full_mock_users"
|
406
|
-
|
407
|
-
before :each do
|
408
|
-
ResourceFullMockUsersController.queryable_with_order
|
409
|
-
ResourceFullMockUser.delete_all
|
410
|
-
|
411
|
-
initech = ResourceFullMockEmployer.create! :name => "Initech", :email => "whatsbestforthecompany@initech.com"
|
412
|
-
tworks = ResourceFullMockEmployer.create! :name => "ThoughtWorks", :email => "info@thoughtworks.com"
|
413
|
-
|
414
|
-
eve = ResourceFullMockUser.create! :first_name => "Eve", :resource_full_mock_employer => initech, :email => "eve@initech.com"
|
415
|
-
alice = ResourceFullMockUser.create! :first_name => "Alice", :resource_full_mock_employer => initech, :email => "alice@initech.com"
|
416
|
-
bob = ResourceFullMockUser.create! :first_name => "Bob", :resource_full_mock_employer => tworks, :email => "bob@thoughtworks.com"
|
417
|
-
|
418
|
-
@ordered_list = [ alice, bob, eve ]
|
419
|
-
@company_ordered_list = [ bob, eve, alice ]
|
420
|
-
end
|
421
|
-
|
422
|
-
it "should be sortable by the given parameter, in ascending order by default" do
|
423
|
-
get :index, :order_by => "first_name"
|
424
|
-
assigns(:resource_full_mock_users).should == @ordered_list
|
425
|
-
end
|
426
|
-
|
427
|
-
it "should be sortable by the given parameter in descending order" do
|
428
|
-
get :index, :order_by => "first_name", :order_direction => "desc"
|
429
|
-
assigns(:resource_full_mock_users).should == @ordered_list.reverse
|
430
|
-
end
|
431
|
-
|
432
|
-
it "should not blow up if no order by key is given" do
|
433
|
-
lambda do
|
434
|
-
get :index
|
435
|
-
end.should_not raise_error(ActiveRecord::StatementInvalid)
|
436
|
-
end
|
437
|
-
|
438
|
-
it "should sort the column with the same table as the resource if no explicit table name is given" do
|
439
|
-
ResourceFullMockUsersController.queryable_with :foo, :scope => { :include => :resource_full_mock_employer }, :default => true
|
440
|
-
lambda do
|
441
|
-
get :index, :order_by => "email"
|
442
|
-
end.should_not raise_error(ActiveRecord::StatementInvalid)
|
443
|
-
assigns(:resource_full_mock_users).should == @ordered_list
|
444
|
-
end
|
445
|
-
|
446
|
-
it "should sort the column with the table name corresponding to the given table name" do
|
447
|
-
ResourceFullMockUsersController.queryable_with :foo, :scope => { :include => :resource_full_mock_employer }, :default => true
|
448
|
-
ResourceFullMockUsersController.orderable_by :email, :from => :resource_full_mock_employer
|
449
|
-
|
450
|
-
get :index, :order_by => "email"
|
451
|
-
assigns(:resource_full_mock_users).first.email.should == "bob@thoughtworks.com"
|
452
|
-
end
|
453
|
-
|
454
|
-
it "should be sortable by the given parameter using the given column" do
|
455
|
-
ResourceFullMockUsersController.orderable_by :employer_email, :from => :resource_full_mock_employer, :column => 'email'
|
456
|
-
|
457
|
-
get :index, :order_by => "employer_email"
|
458
|
-
assigns(:resource_full_mock_users).first.email.should == "bob@thoughtworks.com"
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
|
3
|
-
describe "ResourceFull::Render::JSON" , :type => :controller do
|
4
|
-
controller_name "resource_full_mock_users"
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
ResourceFullMockUser.delete_all
|
8
|
-
ResourceFullMockUsersController.resource_identifier = :id
|
9
|
-
end
|
10
|
-
|
11
|
-
if ([Rails::VERSION::MAJOR, Rails::VERSION::MINOR] <=> [2,1]) >= 0 # if the rails version is 2.1 or greater...
|
12
|
-
it "renders the model object" do
|
13
|
-
user = ResourceFullMockUser.create!
|
14
|
-
get :show, :id => user.id, :format => 'json'
|
15
|
-
user.to_json.should == response.body
|
16
|
-
hash = Hash.from_json(response.body)
|
17
|
-
hash["resource_full_mock_user"].should_not be_nil
|
18
|
-
response.code.should == '200'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "renders the appropriate error message if it can't find the model object" do
|
23
|
-
get :show, :id => 1, :format => 'json'
|
24
|
-
hash = Hash.from_json(response.body)
|
25
|
-
hash["error"]["text"].should == "ActiveRecord::RecordNotFound: not found: 1"
|
26
|
-
response.code.should == '404'
|
27
|
-
end
|
28
|
-
|
29
|
-
it "renders all model objects" do
|
30
|
-
2.times { ResourceFullMockUser.create! }
|
31
|
-
get :index, :format => 'json'
|
32
|
-
hash = Hash.from_json(response.body)
|
33
|
-
hash.size.should == 2
|
34
|
-
response.code.should == '200'
|
35
|
-
end
|
36
|
-
|
37
|
-
it "creates and renders a new model object with an empty body" do
|
38
|
-
put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'json'
|
39
|
-
response.body.should == ResourceFullMockUser.find(:first).to_json
|
40
|
-
ResourceFullMockUser.find(:first).first_name.should == 'brian'
|
41
|
-
end
|
42
|
-
|
43
|
-
it "creates a new model object and returns a status code of 201 (created)" do
|
44
|
-
put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'json'
|
45
|
-
response.code.should == '201'
|
46
|
-
end
|
47
|
-
|
48
|
-
it "creates a new model object and places the location of the new object in the Location header" do
|
49
|
-
put :create, :resource_full_mock_user => {}, :format => 'json'
|
50
|
-
response.headers['Location'].should == resource_full_mock_user_url(ResourceFullMockUser.find(:first))
|
51
|
-
end
|
52
|
-
|
53
|
-
it "renders appropriate errors if a model validation fails" do
|
54
|
-
ResourceFullMockUser.send :define_method, :validate do
|
55
|
-
errors.add :first_name, "can't be blank" if self.first_name.blank?
|
56
|
-
end
|
57
|
-
|
58
|
-
put :create, :resource_full_mock_user => {}, :format => 'json'
|
59
|
-
hash = Hash.from_json(response.body)
|
60
|
-
hash["resource_full_mock_user"]["errors"]["full_messages"][0].should == "First name can't be blank"
|
61
|
-
|
62
|
-
ResourceFullMockUser.send :remove_method, :validate
|
63
|
-
end
|
64
|
-
|
65
|
-
it "renders the JSON for a new model object" do
|
66
|
-
get :new, :format => 'json'
|
67
|
-
response.body.should == ResourceFullMockUser.new.to_json
|
68
|
-
end
|
69
|
-
|
70
|
-
class SomeNonsenseException < Exception; end
|
71
|
-
|
72
|
-
it "rescues all unhandled exceptions with an JSON response" do
|
73
|
-
ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
|
74
|
-
get :index, :format => 'json'
|
75
|
-
hash = Hash.from_json(response.body)
|
76
|
-
hash["error"]["text"].should == "SomeNonsenseException: sparrow farts"
|
77
|
-
end
|
78
|
-
|
79
|
-
it "it sends an exception notification email if ExceptionNotifier is enabled and still renders the JSON error response" do
|
80
|
-
cleanup = unless defined? ExceptionNotifier
|
81
|
-
module ExceptionNotifier; end
|
82
|
-
module ExceptionNotifiable; end
|
83
|
-
true
|
84
|
-
end
|
85
|
-
|
86
|
-
ResourceFullMockUsersController.send :include, ExceptionNotifiable
|
87
|
-
ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
|
88
|
-
ResourceFullMockUsersController.stubs(:exception_data).returns(nil)
|
89
|
-
ResourceFullMockUsersController.any_instance.stubs(:consider_all_requests_local).returns(false)
|
90
|
-
ResourceFullMockUsersController.any_instance.stubs(:local_request?).returns(false)
|
91
|
-
ExceptionNotifier.expects(:deliver_exception_notification)
|
92
|
-
get :index, :format => 'json'
|
93
|
-
hash = Hash.from_json(response.body)
|
94
|
-
hash["error"]["text"].should == "SomeNonsenseException: sparrow farts"
|
95
|
-
|
96
|
-
if cleanup
|
97
|
-
Object.send :remove_const, :ExceptionNotifier
|
98
|
-
Object.send :remove_const, :ExceptionNotifiable
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "retains the generic error 500 when re-rendering unhandled exceptions" do
|
103
|
-
ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
|
104
|
-
get :index, :format => 'json'
|
105
|
-
response.code.should == '500'
|
106
|
-
end
|
107
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
|
3
|
-
describe "ResourceFull::Render::XML" , :type => :controller do
|
4
|
-
controller_name "resource_full_mock_users"
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
ResourceFullMockUser.delete_all
|
8
|
-
ResourceFullMockUsersController.resource_identifier = :id
|
9
|
-
end
|
10
|
-
|
11
|
-
it "renders the model object" do
|
12
|
-
user = ResourceFullMockUser.create!
|
13
|
-
get :show, :id => user.id, :format => 'xml'
|
14
|
-
response.body.should have_tag("resource-full-mock-user")
|
15
|
-
response.code.should == '200'
|
16
|
-
end
|
17
|
-
|
18
|
-
it "renders the appropriate error message if it can't find the model object" do
|
19
|
-
get :show, :id => 1, :format => 'xml'
|
20
|
-
response.body.should have_tag("errors") { with_tag("error", "ActiveRecord::RecordNotFound: not found: 1") }
|
21
|
-
response.code.should == '404'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "renders all model objects" do
|
25
|
-
2.times { ResourceFullMockUser.create! }
|
26
|
-
get :index, :format => 'xml'
|
27
|
-
Hash.from_xml(response.body)['resource_full_mock_users'].size.should == 2
|
28
|
-
response.code.should == '200'
|
29
|
-
end
|
30
|
-
|
31
|
-
it "creates and renders a new model object with an empty body" do
|
32
|
-
put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'xml'
|
33
|
-
response.body.should == ResourceFullMockUser.find(:first).to_xml
|
34
|
-
ResourceFullMockUser.find(:first).first_name.should == 'brian'
|
35
|
-
end
|
36
|
-
|
37
|
-
it "creates a new model object and returns a status code of 201 (created)" do
|
38
|
-
put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'xml'
|
39
|
-
response.code.should == '201'
|
40
|
-
end
|
41
|
-
|
42
|
-
it "creates a new model object and places the location of the new object in the Location header" do
|
43
|
-
put :create, :resource_full_mock_user => {}, :format => 'xml'
|
44
|
-
response.headers['Location'].should == resource_full_mock_user_url(ResourceFullMockUser.find(:first))
|
45
|
-
end
|
46
|
-
|
47
|
-
it "renders appropriate errors if a model validation fails" do
|
48
|
-
ResourceFullMockUser.send :define_method, :validate do
|
49
|
-
errors.add :first_name, "can't be blank" if self.first_name.blank?
|
50
|
-
end
|
51
|
-
|
52
|
-
put :create, :resource_full_mock_user => {}, :format => 'xml'
|
53
|
-
response.should have_tag("errors") { with_tag("error", "First name can't be blank")}
|
54
|
-
|
55
|
-
ResourceFullMockUser.send :remove_method, :validate
|
56
|
-
end
|
57
|
-
|
58
|
-
it "renders the XML for a new model object" do
|
59
|
-
get :new, :format => 'xml'
|
60
|
-
response.body.should == ResourceFullMockUser.new.to_xml
|
61
|
-
end
|
62
|
-
|
63
|
-
class SomeNonsenseException < Exception; end
|
64
|
-
|
65
|
-
it "rescues all unhandled exceptions with an XML response" do
|
66
|
-
ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
|
67
|
-
get :index, :format => 'xml'
|
68
|
-
response.should have_tag("errors") { with_tag("error", "SomeNonsenseException: sparrow farts") }
|
69
|
-
end
|
70
|
-
|
71
|
-
it "it sends an exception notification email if ExceptionNotifier is enabled and still renders the XML error response" do
|
72
|
-
cleanup = unless defined? ExceptionNotifier
|
73
|
-
module ExceptionNotifier; end
|
74
|
-
module ExceptionNotifiable; end
|
75
|
-
true
|
76
|
-
end
|
77
|
-
|
78
|
-
ResourceFullMockUsersController.send :include, ExceptionNotifiable
|
79
|
-
ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
|
80
|
-
ResourceFullMockUsersController.stubs(:exception_data).returns(nil)
|
81
|
-
ResourceFullMockUsersController.any_instance.stubs(:consider_all_requests_local).returns(false)
|
82
|
-
ResourceFullMockUsersController.any_instance.stubs(:local_request?).returns(false)
|
83
|
-
ExceptionNotifier.expects(:deliver_exception_notification)
|
84
|
-
get :index, :format => 'xml'
|
85
|
-
response.should have_tag("errors") { with_tag("error", "SomeNonsenseException: sparrow farts") }
|
86
|
-
|
87
|
-
if cleanup
|
88
|
-
Object.send :remove_const, :ExceptionNotifier
|
89
|
-
Object.send :remove_const, :ExceptionNotifiable
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
it "retains the generic error 500 when re-rendering unhandled exceptions" do
|
94
|
-
ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
|
95
|
-
get :index, :format => 'xml'
|
96
|
-
response.code.should == '500'
|
97
|
-
end
|
98
|
-
end
|