magic_lamp 1.3.1 → 1.4.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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -7
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/magic_lamp/magic_lamp.js +39 -31
  5. data/lib/magic_lamp/fixture_creator.rb +13 -3
  6. data/spec/dummy/log/development.log +30764 -0
  7. data/spec/dummy/log/test.log +19827 -0
  8. data/spec/dummy/spec/magical/magic_lamp.rb +8 -0
  9. data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
  10. data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
  11. data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
  12. data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
  13. data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
  14. data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
  15. data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
  16. data/spec/dummy/tmp/cache/assets/development/sprockets/9825272284630c2926f661645205382a +0 -0
  17. data/spec/dummy/tmp/cache/assets/development/sprockets/b2a142b210c2cbfe4a58040684b3c33c +0 -0
  18. data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
  19. data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
  20. data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
  21. data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
  22. data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
  23. data/spec/dummy/tmp/cache/assets/development/sprockets/fdc3718e0a84d340a897f87179d95c84 +0 -0
  24. data/spec/dummy/tmp/pids/server.pid +1 -0
  25. data/spec/javascripts/genie_spec.js +2 -0
  26. data/spec/javascripts/magic_lamp_spec.js +66 -16
  27. data/spec/lib/fixture_creator_spec.rb +45 -21
  28. metadata +4 -2
@@ -10,3 +10,11 @@ MagicLamp.register_fixture do
10
10
  @order = Order.new
11
11
  render partial: "orders/form"
12
12
  end
13
+
14
+ MagicLamp.fixture(name: "hash_to_jsoned") do
15
+ { foo: "bar" }
16
+ end
17
+
18
+ MagicLamp.fixture(name: "just_some_string") do
19
+ "I'm a super awesome string"
20
+ end
@@ -0,0 +1 @@
1
+ 89870
@@ -152,6 +152,8 @@ describe('Genie', function() {
152
152
  subject.preload();
153
153
  expect(subject.cache).to.have.keys([
154
154
  'from_test_directory',
155
+ 'hash_to_jsoned',
156
+ 'just_some_string',
155
157
  'orders/foo',
156
158
  'orders/bar',
157
159
  'orders/form',
@@ -48,29 +48,25 @@ describe('MagicLamp', function() {
48
48
  });
49
49
 
50
50
  afterEach(function() {
51
- _(['load', 'preload', 'clean']).each(function(method) {
51
+ _(['load', 'loadRaw', 'loadJSON', 'clean']).each(function(method) {
52
52
  delete window[method];
53
53
  });
54
54
  });
55
55
 
56
56
  it('puts #load on window', function() {
57
- expect(window.load).to.be.a('function');
57
+ expect(window.load).to.equal(subject.load);
58
58
  });
59
59
 
60
- it('binds #load', function() {
61
- stub(subject, 'load', true);
62
- load('orders/foo');
63
- expect(subject.load).to.have.been.calledWith('orders/foo');
60
+ it('puts #clean on window', function() {
61
+ expect(window.clean).to.equal(subject.clean);
64
62
  });
65
63
 
66
- it('puts #clean on window', function() {
67
- expect(window.clean).to.be.a('function');
64
+ it('puts #loadRaw on window', function() {
65
+ expect(window.loadRaw).to.equal(subject.loadRaw);
68
66
  });
69
67
 
70
- it('binds #clean', function() {
71
- stub(subject, 'clean', true);
72
- clean();
73
- expect(subject.clean).to.have.been.calledOnce;
68
+ it('puts #loadJSON on window', function() {
69
+ expect(window.loadJSON).to.equal(subject.loadJSON);
74
70
  });
75
71
  });
76
72
 
@@ -78,18 +74,61 @@ describe('MagicLamp', function() {
78
74
  beforeEach(function() {
79
75
  subject.initialize();
80
76
  stub(subject.genie, 'load', true);
81
- subject.load('foo', 'bar', 'baz');
77
+ var dummy = { load: subject.load };
78
+ dummy.load('foo', 'bar', 'baz');
82
79
  });
83
80
 
84
81
  afterEach(function() {
85
82
  delete subject.genie;
86
83
  });
87
84
 
88
- it('passes through to its genie instance', function() {
85
+ it('passes through to its genie instance (and is bound)', function() {
89
86
  expect(subject.genie.load).to.have.been.calledWith('foo', 'bar', 'baz');
90
87
  });
91
88
  });
92
89
 
90
+ describe('#loadRaw', function() {
91
+ var dummy;
92
+ var value;
93
+
94
+ beforeEach(function() {
95
+ subject.initialize();
96
+ value = 'the fixture';
97
+ stub(subject.genie, 'retrieveFixture', value);
98
+ dummy = { loadRaw: subject.loadRaw };
99
+ });
100
+
101
+ afterEach(function() {
102
+ delete subject.genie;
103
+ });
104
+
105
+ it('calls through to its genie\'s #retrieveFixture (and is bound)', function() {
106
+ expect(dummy.loadRaw('foo')).to.equal(value);
107
+ expect(subject.genie.retrieveFixture).to.have.been.calledWith('foo');
108
+ });
109
+ });
110
+
111
+ describe('#loadJSON', function() {
112
+ var json;
113
+ var dummy;
114
+
115
+ beforeEach(function() {
116
+ json = { foo: 'bar' };
117
+ subject.initialize();
118
+ dummy = { loadJSON: subject.loadJSON };
119
+ stub(subject, 'loadRaw', JSON.stringify(json));
120
+ });
121
+
122
+ afterEach(function() {
123
+ delete subject.genie;
124
+ });
125
+
126
+ it('returns the parsed JSON from the fixture (and is bound)', function() {
127
+ expect(dummy.loadJSON('foo')).to.be.like(json);
128
+ expect(subject.loadRaw).to.have.been.calledWith('foo');
129
+ });
130
+ });
131
+
93
132
  describe('#preload', function() {
94
133
  beforeEach(function() {
95
134
  subject.initialize();
@@ -110,14 +149,15 @@ describe('MagicLamp', function() {
110
149
  beforeEach(function() {
111
150
  subject.initialize();
112
151
  stub(subject.genie, 'removeFixtureContainer', true);
113
- subject.clean();
152
+ var dummy = { clean: subject.clean };
153
+ dummy.clean();
114
154
  });
115
155
 
116
156
  afterEach(function() {
117
157
  delete subject.genie;
118
158
  });
119
159
 
120
- it('calls removeFixtureContainer on its genie instance', function() {
160
+ it('calls removeFixtureContainer on its genie instance (and is bound)', function() {
121
161
  expect(subject.genie.removeFixtureContainer).to.have.been.calledOnce;
122
162
  });
123
163
  });
@@ -232,5 +272,15 @@ describe('MagicLamp', function() {
232
272
  subject.load('arbitrary/orders/admin_extending', 'orders/foo');
233
273
  expect(testFixtureContainer().innerHTML).to.equal('Stevenson\nPaulson\nfoo\n');
234
274
  });
275
+
276
+ it('can load JSON', function() {
277
+ var json = subject.loadJSON('hash_to_jsoned');
278
+ expect(json).to.be.like({ foo: 'bar' });
279
+ });
280
+
281
+ it('can load strings', function() {
282
+ var string = subject.loadRaw('just_some_string');
283
+ expect(string).to.equal("I'm a super awesome string");
284
+ });
235
285
  });
236
286
  });
@@ -10,28 +10,56 @@ describe MagicLamp::FixtureCreator do
10
10
  end
11
11
 
12
12
  describe "#generate_template" do
13
- let(:rendered) do
14
- subject.generate_template(OrdersController, []) do
15
- render :foo
13
+ context "render called" do
14
+ let(:rendered) do
15
+ subject.generate_template(OrdersController, []) do
16
+ render :foo
17
+ end
16
18
  end
17
- end
18
19
 
19
- it "returns the template as a string" do
20
- expect(rendered).to eq("foo\n")
21
- end
20
+ it "returns the template as a string" do
21
+ expect(rendered).to eq("foo\n")
22
+ end
22
23
 
23
- it "does not render the layout by default" do
24
- expect(rendered).to_not match(/The layout/)
24
+ it "does not render the layout by default" do
25
+ expect(rendered).to_not match(/The layout/)
26
+ end
27
+
28
+ it "executes the callbacks around generation of the template" do
29
+ dummy = double
30
+ expect(subject).to receive(:execute_before_each_callback).ordered
31
+ expect(dummy).to receive(:render).ordered
32
+ expect(subject).to receive(:execute_after_each_callback).ordered
33
+ subject.generate_template(OrdersController, []) do
34
+ dummy.render
35
+ render :foo
36
+ end
37
+ end
25
38
  end
26
39
 
27
- it "executes the callbacks around generation of the template" do
28
- dummy = double
29
- expect(subject).to receive(:execute_before_each_callback).ordered
30
- expect(dummy).to receive(:render).ordered
31
- expect(subject).to receive(:execute_after_each_callback).ordered
32
- subject.generate_template(OrdersController, []) do
33
- dummy.render
34
- render :foo
40
+ context "render not called" do
41
+ context "render block returns a string" do
42
+ let(:rendered) do
43
+ subject.generate_template(OrdersController, []) do
44
+ { foo: "bar" }.to_json
45
+ end
46
+ end
47
+
48
+ it "returns the string" do
49
+ expect(rendered).to eq({ foo: "bar" }.to_json)
50
+ end
51
+ end
52
+
53
+ context "render block returns someting else" do
54
+ let(:rendered) do
55
+ subject.generate_template(OrdersController, []) do
56
+ { foo: "bar" }
57
+ end
58
+ end
59
+
60
+ it "returns the #to_json representation of the object" do
61
+ expect(rendered).to eq({ foo: "bar" }.to_json)
62
+ end
35
63
  end
36
64
  end
37
65
  end
@@ -60,10 +88,6 @@ describe MagicLamp::FixtureCreator do
60
88
  end.to_not raise_error
61
89
  end
62
90
 
63
- it "has had its state set by the given block" do
64
- expect(controller.params[:foo]).to eq("bar")
65
- end
66
-
67
91
  it "has been extended with the extensions" do
68
92
  expect(controller.class.ancestors).to_not include(Foo)
69
93
  expect(controller.class.ancestors).to_not include(Bar)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic_lamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Crismali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -394,6 +394,7 @@ files:
394
394
  - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
395
395
  - spec/dummy/tmp/cache/assets/test/sprockets/e4468469b981ba614a29626880137332
396
396
  - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
397
+ - spec/dummy/tmp/pids/server.pid
397
398
  - spec/javascripts/genie_spec.js
398
399
  - spec/javascripts/magic_lamp_spec.js
399
400
  - spec/javascripts/spec_helper.js
@@ -605,6 +606,7 @@ test_files:
605
606
  - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
606
607
  - spec/dummy/tmp/cache/assets/test/sprockets/e4468469b981ba614a29626880137332
607
608
  - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
609
+ - spec/dummy/tmp/pids/server.pid
608
610
  - spec/javascripts/genie_spec.js
609
611
  - spec/javascripts/magic_lamp_spec.js
610
612
  - spec/javascripts/spec_helper.js