@@ -9,7 +9,7 @@ class RequirejsRailsTest < ActiveSupport::TestCase
99 assert_kind_of Module , Requirejs ::Rails
1010 assert_kind_of Class , Requirejs ::Rails ::Engine
1111 end
12-
12+
1313 test "require.js version" do
1414 require_js = Pathname . new ( __FILE__ +'/../../vendor/assets/javascripts/require.js' ) . cleanpath . read
1515 context = ExecJS . compile ( require_js )
@@ -51,13 +51,13 @@ def setup
5151
5252 test "user_config should reject baseUrl" do
5353 exc = assert_raises Requirejs ::ConfigError do
54- @cfg . user_config = { 'baseUrl' => '/frobnitz' }
54+ @cfg . user_config = { 'baseUrl' => '/frobnitz' }
5555 end
5656 assert_match /baseUrl is not needed/ , exc . message
5757 end
5858
5959 test "run_config should inherit user_config settings" do
60- @cfg . user_config = { 'paths' => { 'jquery' => 'lib/jquery-1.7.2.min' } }
60+ @cfg . user_config = { 'paths' => { 'jquery' => 'lib/jquery-1.7.2.min' } }
6161 refute_nil @cfg . run_config [ 'paths' ]
6262 assert_kind_of Hash , @cfg . run_config [ 'paths' ]
6363 assert_equal 'lib/jquery-1.7.2.min' , @cfg . run_config [ 'paths' ] [ 'jquery' ]
@@ -69,32 +69,32 @@ def setup
6969 end
7070
7171 test "build_config should inherit user_config settings" do
72- @cfg . user_config = { 'paths' => { 'jquery' => 'lib/jquery-1.7.2.min' } }
72+ @cfg . user_config = { 'paths' => { 'jquery' => 'lib/jquery-1.7.2.min' } }
7373 refute_nil @cfg . build_config [ 'paths' ]
7474 assert_kind_of Hash , @cfg . build_config [ 'paths' ]
7575 assert_equal 'lib/jquery-1.7.2.min' , @cfg . build_config [ 'paths' ] [ 'jquery' ]
7676 end
7777
7878 test "run_config should reject irrelevant settings" do
79- @cfg . user_config = { 'optimize' => 'none' }
80- assert_nil @cfg . run_config [ 'optimize' ]
79+ @cfg . user_config = { 'optimize' => 'none' }
80+ assert_nil @cfg . run_config [ 'optimize' ]
8181 end
8282
8383 test "build_config should reject irrelevant settings" do
84- @cfg . user_config = { 'priority' => %w{ foo bar baz } }
85- assert_nil @cfg . build_config [ 'priority' ]
84+ @cfg . user_config = { 'priority' => %w{ foo bar baz } }
85+ assert_nil @cfg . build_config [ 'priority' ]
8686 end
8787
8888 ## Almond tests
8989 test "build_config with almond should accept one module" do
9090 @cfg . loader = :almond
91- @cfg . user_config = { 'modules' => [ { 'name' => 'foo' } ] }
91+ @cfg . user_config = { 'modules' => [ { 'name' => 'foo' } ] }
9292 assert_match 'almond' , @cfg . build_config [ 'modules' ] [ 0 ] [ 'name' ]
9393 end
9494
9595 test "build_config with almond must reject more than one module" do
9696 @cfg . loader = :almond
97- @cfg . user_config = { 'modules' => [ { 'name' => 'foo' } , { 'name' => 'bar' } ] }
97+ @cfg . user_config = { 'modules' => [ { 'name' => 'foo' } , { 'name' => 'bar' } ] }
9898 exc = assert_raises Requirejs ::ConfigError do
9999 @cfg . build_config
100100 end
@@ -103,7 +103,6 @@ def setup
103103end
104104
105105class RequirejsHelperTest < ActionView ::TestCase
106-
107106 def setup
108107 controller . requirejs_included = false
109108 Rails . application . config . requirejs . user_config = { }
@@ -112,67 +111,88 @@ def setup
112111 end
113112
114113 def with_cdn
115- Rails . application . config . requirejs . user_config = { 'paths' =>
116- { 'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' }
114+ Rails . application . config . requirejs . user_config = {
115+ "paths" => {
116+ "jquery" => "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
117+ }
117118 }
118119 end
119-
120+
120121 def wrap ( tag )
121122 "<html><head>#{ tag } </head></html>"
122123 end
123-
124+
124125 test "requirejs_include_tag" do
125- render :text => wrap ( requirejs_include_tag )
126- assert_select "script:first-of-type" , :text => /var require =/
127- assert_select "script:last-of-type[src^=/javascripts/require.js]" , :count => 1
126+ render text : wrap ( requirejs_include_tag )
127+
128+ assert_select "script:first-of-type[src=\" /javascripts/require.js\" ]" , count : 1
129+ assert_select "script:last-of-type" , text : "require.config({\" baseUrl\" :\" /assets\" });"
128130 end
129-
131+
130132 test "requirejs_include_tag_with_param" do
131- render :text => wrap ( requirejs_include_tag ( "application" ) )
132- assert_select "script:last-of-type[src^=/javascripts/require.js][data-main^=javascripts/application]" , :count => 1
133+ render text : wrap ( requirejs_include_tag ( "application" ) )
134+
135+ assert_select "script:first-of-type[src=\" /javascripts/require.js\" ]" \
136+ "[data-main=\" javascripts/application\" ]" , count : 1
133137 end
134-
138+
135139 test "requirejs_include_tag_with_block" do
136- test_block = Proc . new do | controller |
137- { ' class' => controller . class . to_s . demodulize }
138- end
140+ render text : wrap ( requirejs_include_tag ( "application" ) do
141+ { " class" => controller . class . name . demodulize }
142+ end )
139143
140- render :text => wrap ( requirejs_include_tag ( "application" , & test_block ) )
141- assert_select "script:last-of-type[src^=/javascripts/require.js][ data-main^= javascripts/application]" , :count => 1
142- assert_select "script:last-of-type[src^=/javascripts/require.js][ data-class^= TestController]", : count => 1
144+ assert_select "script:first-of-type[src= \" /javascripts/require.js \" ]" \
145+ "[ data-main= \" javascripts/application\" ]" \
146+ "[ data-class= \" TestController\" ]", count : 1
143147 end
144148
145149 test "requirejs_include_tag can appear only once" do
146150 assert_raises Requirejs ::MultipleIncludeError do
147- render :text => "#{ requirejs_include_tag } \n #{ requirejs_include_tag } "
151+ requirejs_include_tag
152+ requirejs_include_tag
148153 end
149154 end
150155
151- test "requirejs_include_tag with digested asset paths" do
156+ test "requirejs_include_tag with digestified asset paths" do
152157 begin
158+ Rails . application . config . requirejs . user_config = {
159+ "modules" => [
160+ { "name" => "foo" }
161+ ]
162+ }
163+
153164 saved_digest = Rails . application . config . assets . digest
154165 Rails . application . config . assets . digest = true
155- Rails . application . config . requirejs . user_config = { 'modules' => [ { 'name' => 'foo' } ] }
156- render :text => wrap ( requirejs_include_tag )
157- assert_select "script:first-of-type" , :text => %r[var require =.*"paths":{"foo":"/javascripts/foo"}]
166+
167+ render text : wrap ( requirejs_include_tag )
168+
169+ assert_select "script:last-of-type" ,
170+ text : Regexp . new ( "\\ Arequire\\ .config\\ ({.*\" paths\" :{.*\" foo\" :\" /javascripts/foo\" .*}.*}\\ );\\ z" )
158171 ensure
159172 Rails . application . config . assets . digest = saved_digest
160173 end
161174 end
162175
163176 test "requirejs_include_tag with CDN asset in paths" do
164177 with_cdn
165- render :text => wrap ( requirejs_include_tag )
166- assert_select "script:first-of-type" , :text => %r{var require =.*paths.*http://ajax}
178+
179+ render text : wrap ( requirejs_include_tag )
180+
181+ assert_select "script:last-of-type" ,
182+ text : Regexp . new ( "\\ Arequire\\ .config\\ ({.*\" paths\" :{.*\" http://ajax\\ ..*\" .*}.*}\\ );\\ z" )
167183 end
168184
169- test "requirejs_include_tag with CDN asset and digested asset paths" do
185+ test "requirejs_include_tag with CDN asset and digestified asset paths" do
170186 begin
171187 with_cdn
188+
172189 saved_digest = Rails . application . config . assets . digest
173190 Rails . application . config . assets . digest = true
174- render :text => wrap ( requirejs_include_tag )
175- assert_select "script:first-of-type" , :text => %r{var require =.*paths.*http://ajax}
191+
192+ render text : wrap ( requirejs_include_tag )
193+
194+ assert_select "script:last-of-type" ,
195+ text : Regexp . new ( "\\ Arequire\\ .config\\ ({.*\" paths\" :{.*\" http://ajax\\ ..*\" .*}.*}\\ );\\ z" )
176196 ensure
177197 Rails . application . config . assets . digest = saved_digest
178198 end
0 commit comments