Skip to content

Commit 99591cb

Browse files
committed
Improve default_url_options tests
1 parent bad0e82 commit 99591cb

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

spec/js_routes/options_spec.rb

+13-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
evaljs(_presetup) if _presetup
77
with_warnings(_warnings) do
88
evaljs(JsRoutes.generate(_options))
9+
App.routes.default_url_options = _options[:default_url_options] || {}
910
end
1011
end
1112

13+
after(:each) do
14+
App.routes.default_url_options = {}
15+
end
16+
1217
let(:_presetup) { nil }
1318
let(:_options) { {} }
1419
let(:_warnings) { true }
@@ -135,25 +140,25 @@
135140
let(:_warnings) { nil }
136141

137142
it "should render routing with default_format" do
138-
expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1, :format => "json"))
143+
expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
139144
end
140145

141146
it "should render routing with default_format and zero object" do
142-
expect(evaljs("Routes.inbox_path(0)")).to eq(test_routes.inbox_path(0, :format => "json"))
147+
expect(evaljs("Routes.inbox_path(0)")).to eq(test_routes.inbox_path(0))
143148
end
144149

145150
it "should override default_format when spefified implicitly" do
146151
expect(evaljs("Routes.inbox_path(1, {format: 'xml'})")).to eq(test_routes.inbox_path(1, :format => "xml"))
147152
end
148153

149154
it "should override nullify implicitly when specified implicitly" do
150-
expect(evaljs("Routes.inbox_path(1, {format: null})")).to eq(test_routes.inbox_path(1))
155+
expect(evaljs("Routes.inbox_path(1, {format: null})")).to eq(test_routes.inbox_path(1, format: nil))
151156
end
152157

153158

154159
it "shouldn't require the format" do
155160
pending if Rails.version < "4.0"
156-
expect(evaljs("Routes.json_only_path()")).to eq(test_routes.json_only_path(:format => 'json'))
161+
expect(evaljs("Routes.json_only_path()")).to eq(test_routes.json_only_path)
157162
end
158163
end
159164

@@ -201,22 +206,22 @@
201206
context "provided" do
202207
let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
203208
it "should use this opions to fill optional parameters" do
204-
expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path(:optional_id => 12, :format => "json"))
209+
expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path)
205210
end
206211
end
207212

208213
context "not provided" do
209214
let(:_options) { { :default_url_options => { :format => "json" } } }
210215
it "breaks" do
211-
expect(evaljs("Routes.foo_all_path()")).to eq(test_routes.foo_all_path(:format => "json"))
216+
expect(evaljs("Routes.foo_all_path()")).to eq(test_routes.foo_all_path)
212217
end
213218
end
214219
end
215220

216221
context "with required route parts" do
217222
let(:_options) { {:default_url_options => {:inbox_id => "12"}} }
218223
it "should use this opions to fill optional parameters" do
219-
expect(evaljs("Routes.inbox_messages_path()")).to eq(test_routes.inbox_messages_path(:inbox_id => 12))
224+
expect(evaljs("Routes.inbox_messages_path()")).to eq(test_routes.inbox_messages_path)
220225
end
221226
end
222227

@@ -248,7 +253,7 @@
248253
end
249254

250255
it "should remove it by params" do
251-
expect(evaljs("Routes.inbox_path(1, {trailing_slash: false})")).to eq(test_routes.inbox_path(1))
256+
expect(evaljs("Routes.inbox_path(1, {trailing_slash: false})")).to eq(test_routes.inbox_path(1, trailing_slash: false))
252257
end
253258
end
254259

0 commit comments

Comments
 (0)