magic_lamp 0.9.9 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +286 -59
- data/app/assets/javascripts/magic_lamp/genie.js +32 -7
- data/app/assets/javascripts/magic_lamp/magic_lamp.js +4 -0
- data/app/controllers/magic_lamp/fixtures_controller.rb +2 -2
- data/lib/magic_lamp.rb +59 -14
- data/lib/magic_lamp/callbacks.rb +24 -0
- data/lib/magic_lamp/configuration.rb +26 -0
- data/lib/magic_lamp/fixture_creator.rb +6 -5
- data/lib/magic_lamp/render_catcher.rb +17 -10
- data/lib/magic_lamp/version.rb +1 -1
- data/lib/tasks/fixture_names_task.rb +7 -0
- data/lib/tasks/lint_task.rb +8 -0
- data/spec/controllers/magic_lamp/fixtures_controller_spec.rb +2 -2
- data/spec/dummy/log/development.log +74880 -0
- data/spec/dummy/log/test.log +223258 -0
- data/spec/dummy/persisted_specs/magic_lamp.rb +5 -0
- data/spec/dummy/persisted_specs/magic_lamp_config.rb +14 -0
- data/spec/dummy/spec/magical/a_lamp_file_with_a_different_name_lamp.rb +7 -0
- data/spec/dummy/spec/magical/magic_lamp.rb +1 -1
- data/spec/dummy/spec/magical/magic_lamp_config.rb +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/020414588350dc7f6c910d23b47b2eac +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/04a1e26a9e3fde1f448cb2a9d382fbbc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/09bc89d8ac4ccacfcf2f4db466e7735f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0b3144442052dbb8af7f57ca27cd7a15 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b2519cef64d534f944996a2326823f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1e42928536d86174d2365d82a034082b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/292405ba7ff52dbb279572aee49ba174 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2c66f0d7ef22d32ab110fc31a55fe828 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/32b0c6aea545968d6da4939bcbab9b5e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/32d3add1308f63f1ce5eacde1eba7752 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3823434d99b44359ee75dffba2817055 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a2dd1069a3d0cd57769e33920561e09 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3c8cdd0e5d5eee39df490048c656a2c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/40f78fd7fa893a3ba0bb52949d4d6e21 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4878804f69b49fa9eb8a9c0af84ba31a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4af6cefe350f9be6f923a3d72edf1813 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/51333e0ed6511483c511470803d3803a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5723ed075d2604a5ae91531445b2a613 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/58367e9b5bd6d94235a07214faacf926 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5b03eeac2e4ecbaaf227c5aa35808fee +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5c9e5cf4ec642fa40af2267ef88f3095 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5ce07b63a8c04b5207f4ce3e753f5cee +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/62b7a364ac8780cbc8d56c1c6434a0a4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6f968441247482ba7e1ac7ce9f34dfdb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/759e97d6d411bc4cef7055a778e1bef3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7f5b2f45d9f12db1fb26a605759b360a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7f7dcf7837dbb7f150b7364ad7920712 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/80a68d71946643e61d91cc216f7aa32f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/86023efec2465a88617e5a47a38f1f55 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/87c6d9a5c985ccb321255862fd8c2f48 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8a0862dca044d19cadb655c53acb20ab +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8c4d5b82ba38d47cebae9c56db8fc883 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8dc2cb33d4af3c73661b4b84b4a95947 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8e2a04fd6b5a2e086e5d604cb8224809 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8f4a370f455559b7a209ecd758a3bb3d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9825272284630c2926f661645205382a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9d676cb2f7cb26509cfcd0bce3f08fee +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/acbd4771ecb2a173a35382fbff9317cf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b226a96bfa85a5a853dd6566d1706231 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b29390c73fea05dd0073f043c17a9986 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b2a142b210c2cbfe4a58040684b3c33c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bb57f340ac9df9041014540af079a7f3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bfa154e8a12acdbc85028ad8130d9043 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c84af5f8f55b15818667b16b15416431 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d53d8d895a44b860d5e1399e1a9a7b69 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d5b28f340e57aab871a83d30b1294b62 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e52d001ef73b04129baa586e2822018e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f12e838fbbcc1647156ec47ebbeaac9a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f3018c23e25ab4b02fc51d6302f79a0a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f30abc368796858ff89a5ff6daf33e6a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f5e8036e8de24870e4db21ccb209e272 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f62fb3331d14ad448ad997f1fbdb7e23 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fd203e335fb22b3109d0354b99f45c6e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fdc3718e0a84d340a897f87179d95c84 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/javascripts/genie_spec.js +97 -28
- data/spec/javascripts/magic_lamp_spec.js +50 -17
- data/spec/javascripts/spec_helper.js +5 -4
- data/spec/javascripts/support/chai-fuzzy.js +110 -0
- data/spec/lib/callbacks_spec.rb +58 -0
- data/spec/lib/configuration_spec.rb +48 -0
- data/spec/lib/fixture_creator_spec.rb +17 -14
- data/spec/lib/magic_lamp_spec.rb +97 -26
- data/spec/lib/render_catcher_spec.rb +18 -4
- data/spec/rails_helper.rb +2 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/tasks/fixture_names_task_spec.rb +23 -0
- data/spec/tasks/lint_task_spec.rb +17 -0
- data/spec/teaspoon_env.rb +33 -34
- metadata +146 -9
- data/lib/tasks/magic_lamp_tasks.rake +0 -4
- data/spec/dummy/tmp/pids/server.pid +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MagicLamp.registered_fixtures
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -28,6 +28,26 @@ describe('Genie', function() {
|
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
+
describe('#fixtureNames', function() {
|
|
32
|
+
beforeEach(function() {
|
|
33
|
+
stub(console, 'log', true);
|
|
34
|
+
subject.cache = { foo: 'template', bar: 'other template' };
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('returns all of the fixtures named in the cache', function() {
|
|
38
|
+
expect(subject.fixtureNames()).to.be.like(['bar', 'foo']);
|
|
39
|
+
console.log.restore();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('logs all of the fixture names in the cache', function() {
|
|
43
|
+
subject.fixtureNames();
|
|
44
|
+
expect(console.log).to.have.been.calledWith('bar');
|
|
45
|
+
expect(console.log).to.have.been.calledWith('foo');
|
|
46
|
+
expect(console.log.args).to.be.like([['bar'], ['foo']]);
|
|
47
|
+
console.log.restore();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
31
51
|
describe('#load', function() {
|
|
32
52
|
var path;
|
|
33
53
|
beforeEach(function() {
|
|
@@ -38,6 +58,13 @@ describe('Genie', function() {
|
|
|
38
58
|
removeNode(subject.fixtureContainer);
|
|
39
59
|
});
|
|
40
60
|
|
|
61
|
+
it('does not double append fixture containers', function() {
|
|
62
|
+
subject.cache[path] = 'some template';
|
|
63
|
+
subject.cacheOnly = true;
|
|
64
|
+
_(2).times(function() { subject.load(path); });
|
|
65
|
+
expect(document.getElementsByClassName('magic-lamp').length).to.equal(1);
|
|
66
|
+
});
|
|
67
|
+
|
|
41
68
|
describe('cacheOnly false', function() {
|
|
42
69
|
it('requests the fixture and adds it to the cache', function() {
|
|
43
70
|
spyOn(subject, 'xhrRequest');
|
|
@@ -47,12 +74,11 @@ describe('Genie', function() {
|
|
|
47
74
|
});
|
|
48
75
|
|
|
49
76
|
it('appends the fixture container with the fixture to the dom', function() {
|
|
50
|
-
expect(testFixtureContainer()).to.
|
|
77
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
51
78
|
subject.load(path);
|
|
52
79
|
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
|
53
80
|
});
|
|
54
81
|
|
|
55
|
-
|
|
56
82
|
describe('cached', function() {
|
|
57
83
|
beforeEach(function() {
|
|
58
84
|
subject.cache[path] = 'howdy';
|
|
@@ -65,7 +91,7 @@ describe('Genie', function() {
|
|
|
65
91
|
});
|
|
66
92
|
|
|
67
93
|
it('appends the fixture container to the dom with the cached fixture', function() {
|
|
68
|
-
expect(testFixtureContainer()).to.
|
|
94
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
69
95
|
subject.load(path);
|
|
70
96
|
expect(testFixtureContainer().innerHTML).to.equal('howdy');
|
|
71
97
|
});
|
|
@@ -87,7 +113,7 @@ describe('Genie', function() {
|
|
|
87
113
|
it('throws an error if the fixture is not in the cache', function() {
|
|
88
114
|
expect(function() {
|
|
89
115
|
subject.load(path);
|
|
90
|
-
}).to.throw(/The fixture "orders\/foo" was not preloaded. Is the fixture registered\?
|
|
116
|
+
}).to.throw(/The fixture "orders\/foo" was not preloaded. Is the fixture registered\? Call `MagicLamp.fixtureNames\(\)` to see what is registered./);
|
|
91
117
|
});
|
|
92
118
|
});
|
|
93
119
|
});
|
|
@@ -95,7 +121,7 @@ describe('Genie', function() {
|
|
|
95
121
|
describe('#preload', function() {
|
|
96
122
|
it('requests all of the fixtures and puts them in the cache', function() {
|
|
97
123
|
subject.preload();
|
|
98
|
-
expect(subject.cache).to.have.keys(['orders/foo', 'orders/bar', 'orders/form']);
|
|
124
|
+
expect(subject.cache).to.have.keys(['orders/foo', 'orders/bar', 'orders/form', 'custom_name', 'super_specified']);
|
|
99
125
|
});
|
|
100
126
|
|
|
101
127
|
it('sets cacheOnly to true', function() {
|
|
@@ -103,6 +129,12 @@ describe('Genie', function() {
|
|
|
103
129
|
expect(subject.cacheOnly).to.equal(true);
|
|
104
130
|
});
|
|
105
131
|
|
|
132
|
+
it('does not set cacheOnly to true if the request fails', function() {
|
|
133
|
+
subject.xhrRequest = function() { throw new Error(); }
|
|
134
|
+
expect(function() { subject.preload(); }).to.throw();
|
|
135
|
+
expect(subject.cacheOnly).to.equal(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
106
138
|
it('makes a request to the specified path if defined', function() {
|
|
107
139
|
var path = MagicLamp.path = '/normal_lamp';
|
|
108
140
|
stub(subject, 'xhrRequest', { responseText: '{}' });
|
|
@@ -115,17 +147,17 @@ describe('Genie', function() {
|
|
|
115
147
|
});
|
|
116
148
|
|
|
117
149
|
describe('#createFixtureContainer', function() {
|
|
118
|
-
it('creates a div with
|
|
150
|
+
it('creates a div with a class of "magic-lamp" and caches it', function() {
|
|
119
151
|
subject.createFixtureContainer();
|
|
120
152
|
expect(subject.fixtureContainer.tagName).to.equal('DIV');
|
|
121
|
-
expect(subject.fixtureContainer.
|
|
153
|
+
expect(subject.fixtureContainer.className).to.equal('magic-lamp');
|
|
122
154
|
});
|
|
123
155
|
|
|
124
|
-
it('creates a div with
|
|
125
|
-
var
|
|
156
|
+
it('creates a div with a class of MagicLamp.class if present', function() {
|
|
157
|
+
var specifiedClass = MagicLamp.class = 'footastic';
|
|
126
158
|
subject.createFixtureContainer();
|
|
127
|
-
delete MagicLamp.
|
|
128
|
-
expect(subject.fixtureContainer.
|
|
159
|
+
delete MagicLamp.class;
|
|
160
|
+
expect(subject.fixtureContainer.className).to.equal(specifiedClass);
|
|
129
161
|
});
|
|
130
162
|
});
|
|
131
163
|
|
|
@@ -139,34 +171,57 @@ describe('Genie', function() {
|
|
|
139
171
|
});
|
|
140
172
|
|
|
141
173
|
it('appends the fixtureContainer to the body', function() {
|
|
142
|
-
expect(testFixtureContainer()).to.
|
|
174
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
143
175
|
subject.appendFixtureContainer();
|
|
144
176
|
expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
|
|
145
177
|
});
|
|
146
178
|
});
|
|
147
179
|
|
|
148
180
|
describe('#removeFixtureContainer', function() {
|
|
149
|
-
beforeEach(function() {
|
|
150
|
-
subject.createFixtureContainer();
|
|
151
|
-
subject.appendFixtureContainer();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
181
|
afterEach(function() {
|
|
155
182
|
removeNode(subject.fixtureContainer);
|
|
156
183
|
});
|
|
157
184
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
185
|
+
describe('without the fixture container', function() {
|
|
186
|
+
it('logs a message saying that this is a weird thing to do', function() {
|
|
187
|
+
expect(function() {
|
|
188
|
+
_(3).times(function() { subject.removeFixtureContainer(); });
|
|
189
|
+
}).to.not.throw()
|
|
190
|
+
});
|
|
163
191
|
});
|
|
164
192
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
193
|
+
describe('with the fixture container created', function() {
|
|
194
|
+
beforeEach(function() {
|
|
195
|
+
subject.createFixtureContainer();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('removes the fixture container from the genie instance', function() {
|
|
199
|
+
expect(subject.fixtureContainer).to.be.defined;
|
|
200
|
+
subject.removeFixtureContainer();
|
|
201
|
+
expect(subject.fixtureContainer).to.be.undefined;
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('with the fixture there', function() {
|
|
206
|
+
beforeEach(function() {
|
|
207
|
+
subject.createFixtureContainer();
|
|
208
|
+
subject.appendFixtureContainer();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('removes the fixture container from the dom', function() {
|
|
212
|
+
expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
|
|
213
|
+
subject.removeFixtureContainer();
|
|
214
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
215
|
+
expect(subject.fixtureContainer).to.be.undefined;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('removes the fixture container from the genie instance', function() {
|
|
219
|
+
expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
|
|
220
|
+
subject.removeFixtureContainer();
|
|
221
|
+
expect(subject.fixtureContainer).to.be.undefined;
|
|
222
|
+
});
|
|
169
223
|
});
|
|
224
|
+
|
|
170
225
|
});
|
|
171
226
|
|
|
172
227
|
describe('#handleError', function() {
|
|
@@ -190,7 +245,6 @@ describe('Genie', function() {
|
|
|
190
245
|
|
|
191
246
|
expect(xhrProto.open).to.have.been.calledWith('GET', path, false);
|
|
192
247
|
expect(xhrProto.send).to.have.been.calledOnce;
|
|
193
|
-
|
|
194
248
|
});
|
|
195
249
|
|
|
196
250
|
it('returns the xhr object', function() {
|
|
@@ -200,11 +254,26 @@ describe('Genie', function() {
|
|
|
200
254
|
expect(result.constructor).to.equal(XMLHttpRequest);
|
|
201
255
|
});
|
|
202
256
|
|
|
203
|
-
it('calls handleError if the status
|
|
257
|
+
it('calls handleError with the response text if the status was 400', function() {
|
|
204
258
|
stub(subject, 'handleError', true);
|
|
205
259
|
var path = '/magic_lamp/foo/bar';
|
|
206
260
|
var xhr = subject.xhrRequest(path);
|
|
207
261
|
expect(subject.handleError).to.have.been.calledWith(xhr.responseText);
|
|
208
262
|
});
|
|
263
|
+
|
|
264
|
+
it('calls handleError with the default error message if the status was 500', function() {
|
|
265
|
+
stub(subject, 'handleError', true);
|
|
266
|
+
stub(subject, 'xhrStatus', 500);
|
|
267
|
+
var path = '/magic_lamp/foo/bar';
|
|
268
|
+
var xhr = subject.xhrRequest(path);
|
|
269
|
+
expect(subject.handleError).to.have.been.calledWith('Something went wrong while generating the fixture, please check the server log or run `rake magic_lamp:lint` for more information');
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe('#xhrStatus', function() {
|
|
274
|
+
it('returns the status of the xhr', function() {
|
|
275
|
+
var status = 200;
|
|
276
|
+
expect(subject.xhrStatus({ status: status })).to.equal(status);
|
|
277
|
+
});
|
|
209
278
|
});
|
|
210
279
|
});
|
|
@@ -22,6 +22,26 @@ describe('MagicLamp', function() {
|
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
describe('#fixtureNames', function() {
|
|
26
|
+
beforeEach(function() {
|
|
27
|
+
subject.initialize();
|
|
28
|
+
stub(subject.genie, 'fixtureNames', true);
|
|
29
|
+
subject.fixtureNames();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(function() {
|
|
33
|
+
delete subject.genie;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('passes through to its genie instance', function() {
|
|
37
|
+
expect(subject.genie.fixtureNames).to.have.been.calledOnce;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('returns the genie instance\'s return value', function() {
|
|
41
|
+
expect(subject.fixtureNames()).to.equal(true);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
25
45
|
describe('#globalize', function() {
|
|
26
46
|
beforeEach(function() {
|
|
27
47
|
subject.globalize();
|
|
@@ -130,47 +150,50 @@ describe('MagicLamp', function() {
|
|
|
130
150
|
});
|
|
131
151
|
|
|
132
152
|
afterEach(function() {
|
|
153
|
+
subject.clean();
|
|
133
154
|
delete subject.genie;
|
|
134
155
|
});
|
|
135
156
|
|
|
136
157
|
it('can load the foo template and clean up', function() {
|
|
137
|
-
expect(testFixtureContainer()).to.
|
|
158
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
138
159
|
subject.load('orders/foo');
|
|
139
160
|
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
|
140
161
|
subject.clean();
|
|
141
|
-
expect(testFixtureContainer()).to.
|
|
162
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
142
163
|
});
|
|
143
164
|
|
|
144
165
|
it('can preload the templates and clean up', function() {
|
|
145
166
|
subject.preload();
|
|
146
|
-
expect(testFixtureContainer()).to.
|
|
147
|
-
subject.load('orders/foo');
|
|
167
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
168
|
+
_(2).times(function() { subject.load('orders/foo'); });
|
|
169
|
+
expect(document.getElementsByClassName('magic-lamp').length).to.equal(1);
|
|
148
170
|
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
|
149
171
|
subject.clean();
|
|
150
|
-
expect(testFixtureContainer()).to.
|
|
172
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
151
173
|
subject.load('orders/bar');
|
|
152
174
|
expect(testFixtureContainer().innerHTML).to.equal('bar\n');
|
|
153
|
-
subject.clean();
|
|
154
|
-
expect(testFixtureContainer()).to.
|
|
175
|
+
_(3).times(function() { subject.clean(); });
|
|
176
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
155
177
|
});
|
|
156
178
|
|
|
157
|
-
it('can specify the
|
|
158
|
-
var
|
|
179
|
+
it('can specify the class used for the fixture container', function() {
|
|
180
|
+
var newClass = subject.class = 'the-eye';
|
|
159
181
|
subject.load('orders/foo');
|
|
160
|
-
expect(testFixtureContainer()).to.
|
|
161
|
-
expect(
|
|
162
|
-
expect(
|
|
182
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
183
|
+
expect(findByClassName(newClass)).to.exist;
|
|
184
|
+
expect(findByClassName(newClass).innerHTML).to.equal('foo\n');
|
|
163
185
|
subject.clean();
|
|
164
|
-
expect(
|
|
165
|
-
delete subject.
|
|
186
|
+
expect(findByClassName(newClass)).to.not.exist;
|
|
187
|
+
delete subject.class;
|
|
166
188
|
});
|
|
167
189
|
|
|
168
190
|
it('throws an error when it cannot find the template', function() {
|
|
169
191
|
expect(function() {
|
|
170
192
|
subject.load('not/gonna/happen');
|
|
171
193
|
}).to.throw(/'not\/gonna\/happen' is not a registered fixture$/);
|
|
172
|
-
|
|
173
|
-
|
|
194
|
+
_(3).times(function() { subject.clean(); });
|
|
195
|
+
subject.clean();
|
|
196
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
174
197
|
});
|
|
175
198
|
|
|
176
199
|
it('throws an error when it cannot find the preloaded template', function() {
|
|
@@ -178,8 +201,18 @@ describe('MagicLamp', function() {
|
|
|
178
201
|
expect(function() {
|
|
179
202
|
subject.load('still/not/gonna/happen');
|
|
180
203
|
}).to.throw();
|
|
204
|
+
_(3).times(function() { subject.clean(); });
|
|
205
|
+
expect(testFixtureContainer()).to.be.undefined;
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('can load fixtures with specified names', function() {
|
|
209
|
+
subject.load('custom_name');
|
|
210
|
+
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
|
211
|
+
});
|
|
181
212
|
|
|
182
|
-
|
|
213
|
+
it('can load fixtures with specified names and controllers', function() {
|
|
214
|
+
subject.load('super_specified')
|
|
215
|
+
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
|
183
216
|
});
|
|
184
217
|
});
|
|
185
218
|
});
|