@@ -44,6 +44,57 @@ def setup
44
44
@cfg . logical_asset_filter += [ /\. frobnitz$/ ]
45
45
assert_equal true , @cfg . asset_allowed? ( 'bar.frobnitz' )
46
46
end
47
+
48
+ test "should have a default empty user_config" do
49
+ assert_kind_of Hash , @cfg . user_config
50
+ end
51
+
52
+ test "user_config should reject baseUrl" do
53
+ exc = assert_raises Requirejs ::ConfigError do
54
+ @cfg . user_config = { "baseUrl" => "/frobnitz" }
55
+ end
56
+ assert_match /baseUrl is not needed/ , exc . message
57
+ end
58
+
59
+ test "run_config should inherit user_config settings" do
60
+ @cfg . user_config = { 'paths' => { 'jquery' => 'lib/jquery-1.7.2.min' } }
61
+ refute_nil @cfg . run_config [ 'paths' ]
62
+ assert_kind_of Hash , @cfg . run_config [ 'paths' ]
63
+ assert_equal 'lib/jquery-1.7.2.min' , @cfg . run_config [ 'paths' ] [ 'jquery' ]
64
+ end
65
+
66
+ test "build_config should inherit user_config settings" do
67
+ @cfg . user_config = { 'paths' => { 'jquery' => 'lib/jquery-1.7.2.min' } }
68
+ refute_nil @cfg . build_config [ 'paths' ]
69
+ assert_kind_of Hash , @cfg . build_config [ 'paths' ]
70
+ assert_equal 'lib/jquery-1.7.2.min' , @cfg . build_config [ 'paths' ] [ 'jquery' ]
71
+ end
72
+
73
+ test "run_config should reject irrelevant settings" do
74
+ @cfg . user_config = { 'optimize' => 'none' }
75
+ assert_nil @cfg . run_config [ 'optimize' ]
76
+ end
77
+
78
+ test "build_config should reject irrelevant settings" do
79
+ @cfg . user_config = { 'priority' => %w{ foo bar baz } }
80
+ assert_nil @cfg . build_config [ 'priority' ]
81
+ end
82
+
83
+ ## Almond tests
84
+ test "build_config with almond should accept one module" do
85
+ @cfg . loader = :almond
86
+ @cfg . user_config = { 'modules' => [ { 'name' => 'foo' } ] }
87
+ assert_match 'almond' , @cfg . build_config [ 'modules' ] [ 0 ] [ 'name' ]
88
+ end
89
+
90
+ test "build_config with almond must reject more than one module" do
91
+ @cfg . loader = :almond
92
+ @cfg . user_config = { 'modules' => [ { 'name' => 'foo' } , { 'name' => 'bar' } ] }
93
+ exc = assert_raises Requirejs ::ConfigError do
94
+ @cfg . build_config
95
+ end
96
+ assert_match /requires exactly one module/ , exc . message
97
+ end
47
98
end
48
99
49
100
class RequirejsHelperTest < ActionView ::TestCase
0 commit comments