magic_lamp 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24d10bfc30e19c36245d5a06668c291d78974e95
4
- data.tar.gz: b927c195fc7bcf1cb16ea7d9779cfe00f60596c1
3
+ metadata.gz: 59341749511aa8a67d1add3ab349b34efdf2ed38
4
+ data.tar.gz: 281fb70cc9c9bfacee96a46840aca2e8d619988a
5
5
  SHA512:
6
- metadata.gz: fa83054ff11497292adf67fd25e1b485eabc4640f4ab9603368ddb5c2724edcf679ba40da953e0f37f5d8c565a9d08cc0198afa3ab9358980c943fc2517d9a6f
7
- data.tar.gz: 8dda7d8275c106a2492613fc35d55140589e95291fa3851835f42c20fa426408d7779e9055accb0929597d83f953edc481bd18f9945189a744446dcfb4a8d13f
6
+ metadata.gz: 531159bceb7d43fa85994b61834cbb3e503b1eae418e70102b5fa50d27835273b2ad2b0b40c972308e3555c41a6ef3557dbb8faccf80fa2fea641f45286c9737
7
+ data.tar.gz: 31a71c1c45690d3a65a2260f4b39301477d536f3496ff159a9f4a0d8e3fe694d06db45072eae1bad1ae186383788cdde327f2bf0bf53c6f45c793198f7dbc7e7
data/README.md CHANGED
@@ -46,7 +46,7 @@ Then drop this:
46
46
  ```
47
47
  at the top of your `spec_helper.js` (assuming you're using JavaScript spec runner for Rails that allows the use of Sprockets directives).
48
48
 
49
- If your JavaScript doesn't support XHR requests, you can drop this in instead:
49
+ If your JavaScript test runner doesn't support XHR requests, you can drop this in instead:
50
50
 
51
51
  ```js
52
52
  //= require magic_lamp
@@ -531,14 +531,28 @@ describe("Foo", function() {
531
531
  ```
532
532
  Errors
533
533
  ------
534
- If there are errors rendering any of your templates, Magic Lamp will often throw a JavaScript
535
- error. Errors will also appear in your server log (if you're running the in-browser specs).
534
+ If there are errors rendering any of your templates, Magic Lamp will often throw a JavaScript error. Errors will also appear in your server log (if you're running the in-browser specs).
536
535
 
537
536
  To see errors outside of the server log (which may be noisy), you can run [`rake magic_lamp:lint`](#tasks) (or `rake mll`) or visit `/magic_lamp/lint` in your browser and display any errors in your fixtures.
538
537
 
538
+ You can debug into your fixture generation code or even the templates themselves just as you normally would in any other part of your Rails app. If you start seeing a bunch of `RenderCatcher` objects instead of the code you expected, just continue through and wait for the debugger to catch again and things go back to normal. If you want to skip continuing through, simply provide an explicit name for the fixture.
539
+
539
540
  If you get an `ActionView::MissingTemplate` error, try specifying the controller. This error is caused by a template that renders a partial
540
541
  without using the fully qualified path to the partial. Specifying the controller should help Rails find the template.
541
542
 
543
+ When rails is inferring routes for `form_for`, `link_to`, and a few other methods you'll sometimes need to change `request.env["action_dispatch.request.path_parameters"]` by setting `action` and `controller`. When the route is nested with with a parameter in the url like `/orders/:order_id/foos/new` you'll need to add the `:order_id` to it like so:
544
+
545
+ ```ruby
546
+ fixture do
547
+ request.env["action_dispatch.request.path_parameters"] = {
548
+ action: "new",
549
+ controller: "foos",
550
+ order_id: 3
551
+ }
552
+ render :new
553
+ end
554
+ ```
555
+
542
556
  Sweet aliases
543
557
  -------------
544
558
  ### Ruby
@@ -25,12 +25,17 @@
25
25
  retrieveFixture: function(path) {
26
26
  var fixture = this.cache[path];
27
27
 
28
+ throwEmptyFixtureErrorIfEmpty(fixture, path);
29
+
28
30
  if (!fixture && this.cacheOnly) {
29
31
  throw new Error('The fixture "' + path + '" was not preloaded. Is the fixture registered? Call `MagicLamp.fixtureNames()` to see what is registered.');
30
32
  } else if (!fixture) {
31
33
  var xhr = this.xhrRequest(getPath() + '/' + path);
32
34
  this.cache[path] = fixture = xhr.responseText;
33
35
  }
36
+
37
+ throwEmptyFixtureErrorIfEmpty(fixture, path);
38
+
34
39
  return fixture;
35
40
  },
36
41
 
@@ -112,6 +117,12 @@
112
117
  };
113
118
  }
114
119
 
120
+ function throwEmptyFixtureErrorIfEmpty(fixture, path) {
121
+ if (fixture === '') {
122
+ throw new Error('The fixture "' + path + '" is an empty string. Run `rake magic_lamp:lint` for more information.');
123
+ }
124
+ }
125
+
115
126
  function newXhr() {
116
127
  var xhr;
117
128
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
@@ -15,5 +15,6 @@ module MagicLamp
15
15
  ArgumentError = Class.new(StandardError)
16
16
  AttemptedRedirectError = Class.new(StandardError)
17
17
  DoubleRenderError = Class.new(StandardError)
18
+ EmptyFixtureError = Class.new(StandardError)
18
19
  UnregisteredFixtureError = Class.new(StandardError)
19
20
  end
@@ -5,11 +5,17 @@ module MagicLamp
5
5
  attr_accessor :render_arguments
6
6
 
7
7
  def generate_template(controller_class, extensions, &block)
8
- execute_callbacks_around do
8
+ fixture = execute_callbacks_around do
9
9
  controller = new_controller(controller_class, extensions, &block)
10
10
  controller.request.env["action_dispatch.request.path_parameters"] = { action: "index", controller: controller.controller_name }
11
11
  fetch_rendered(controller, block)
12
12
  end
13
+
14
+ if fixture.empty?
15
+ raise EmptyFixtureError, "Fixture was an empty string. This is probably not what you meant to have happen."
16
+ end
17
+
18
+ fixture
13
19
  end
14
20
 
15
21
  def new_controller(controller_class, extensions, &block)
@@ -1,3 +1,3 @@
1
1
  module MagicLamp
2
- VERSION = "1.6.2"
2
+ VERSION = "1.7.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  MagicLamp.fixture(name: "from_test_directory") do
2
- render text: ""
2
+ render text: "something something"
3
3
  end
@@ -105,6 +105,13 @@ describe('Genie', function() {
105
105
  expect(subject.retrieveFixture(path)).to.equal(fixtureContent);
106
106
  });
107
107
 
108
+ it('throws an error if the fixture is an empty string', function() {
109
+ stub(subject, 'xhrRequest', { responseText: '' });
110
+ expect(function() {
111
+ subject.retrieveFixture(path);
112
+ }).to.throw(/The fixture "orders\/foo" is an empty string. Run `rake magic_lamp:lint` for more information./);
113
+ });
114
+
108
115
  describe('cached', function() {
109
116
  beforeEach(function() {
110
117
  fixtureContent = subject.cache[path] = 'howdy';
@@ -119,6 +126,13 @@ describe('Genie', function() {
119
126
  it('returns the fixture', function() {
120
127
  expect(subject.retrieveFixture(path)).to.equal(fixtureContent);
121
128
  });
129
+
130
+ it('throws an error if the fixture is an empty string', function() {
131
+ subject.cache[path] = '';
132
+ expect(function() {
133
+ subject.retrieveFixture(path);
134
+ }).to.throw(/The fixture "orders\/foo" is an empty string. Run `rake magic_lamp:lint` for more information./);
135
+ });
122
136
  });
123
137
  });
124
138
 
@@ -144,6 +158,13 @@ describe('Genie', function() {
144
158
  subject.retrieveFixture(path);
145
159
  }).to.throw(/The fixture "orders\/foo" was not preloaded. Is the fixture registered\? Call `MagicLamp.fixtureNames\(\)` to see what is registered./);
146
160
  });
161
+
162
+ it('throws an error if the fixture is an empty string', function() {
163
+ subject.cache[path] = '';
164
+ expect(function() {
165
+ subject.retrieveFixture(path);
166
+ }).to.throw(/The fixture "orders\/foo" is an empty string. Run `rake magic_lamp:lint` for more information./);
167
+ });
147
168
  });
148
169
  });
149
170
 
@@ -90,6 +90,16 @@ describe MagicLamp::FixtureCreator do
90
90
  end
91
91
  end
92
92
  end
93
+
94
+ context "fixture is empty" do
95
+ it "raises an error" do
96
+ expect do
97
+ subject.generate_template(OrdersController, []) do
98
+ ""
99
+ end
100
+ end.to raise_error(MagicLamp::EmptyFixtureError, /fixture was an empty string. This is probably not what you meant to have happen./i)
101
+ end
102
+ end
93
103
  end
94
104
 
95
105
  describe "#new_controller" do
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.6.2
4
+ version: 1.7.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: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails