render_with_view 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Rakefile +9 -0
- data/lib/render_with_view.rb +1 -0
- data/lib/render_with_view/version.rb +1 -1
- data/render_with_view.gemspec +16 -0
- data/spec/render_with_view/half_open_struct_spec.rb +45 -0
- data/spec/render_with_view/rspec_matcher_spec.rb +21 -0
- data/spec/render_with_view_spec.rb +39 -0
- data/spec/spec_helper.rb +16 -0
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 635dffd60e128b0e6d0aff1fa43ca4b796bcab64
|
4
|
+
data.tar.gz: e5ac59a8114b559f1c55be13040f130cbaa7dc8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19d89f2f02b1f757689b94700cdb2fc68dd73b0d8438e9729f0895fc82220ed5d142c4a2c1f2dfcd0459520afac1d218d2ccb6c77f0de994d0e449e3ebe4e17f
|
7
|
+
data.tar.gz: 667de2408b432bc7b47598d0b458428d297b2c2a50eb151caa732529006fcb5400ba267687a0af443bb0524e5fbd733a30594c88f239285f925c1320bb688fdf
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/render_with_view.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path("../lib/render_with_view/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'render_with_view'
|
6
|
+
s.summary = 'Be explicit about what you send to your Rails views'
|
7
|
+
s.version = RenderWithView::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Mikkel Malmberg']
|
10
|
+
s.email = ['mikkel@brnbw.com']
|
11
|
+
s.homepage = 'https://github.com/mikker/render_with_view'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_path = "lib"
|
16
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RenderWithView
|
4
|
+
RSpec.describe HalfOpenStruct do
|
5
|
+
it "can be initialized with a hash, and values read and written" do
|
6
|
+
s = HalfOpenStruct.new(name: "Joe")
|
7
|
+
expect(s.name).to eq "Joe"
|
8
|
+
|
9
|
+
s.age = 42
|
10
|
+
expect(s.age).to eq 42
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises trying to read an unknown value" do
|
14
|
+
s = HalfOpenStruct.new
|
15
|
+
|
16
|
+
expect { s.age }.to raise_error("Unknown key: age")
|
17
|
+
|
18
|
+
s.age = 42
|
19
|
+
expect(s.age).to eq 42
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises for unknown methods" do
|
23
|
+
s = HalfOpenStruct.new
|
24
|
+
|
25
|
+
expect { s.foo("bar") }.to raise_error(NoMethodError)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Considered an API like "s.age?" but that's ambiguous with undefined vs. falsy values.
|
29
|
+
it "lets you query for values being defined" do
|
30
|
+
s = HalfOpenStruct.new
|
31
|
+
expect(s.include?(:age)).to be false
|
32
|
+
|
33
|
+
s.age = 42
|
34
|
+
expect(s.include?(:age)).to be true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "lets you fetch values with a fallback" do
|
38
|
+
s = HalfOpenStruct.new
|
39
|
+
expect(s.fetch(:age, :fallback)).to eq :fallback
|
40
|
+
|
41
|
+
s.age = 42
|
42
|
+
expect(s.fetch(:age, :fallback)).to eq 42
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'render_with_view/rspec_matcher'
|
3
|
+
|
4
|
+
RSpec.describe 'RSpec matcher' do
|
5
|
+
let(:ctrl) { FakeController.new }
|
6
|
+
subject { ctrl.render_with_view :index, thing: 1 }
|
7
|
+
|
8
|
+
# short form
|
9
|
+
it { should set_view_local :thing }
|
10
|
+
it { should_not set_view_local :other_thing }
|
11
|
+
|
12
|
+
# long form
|
13
|
+
it "takes and matches arguments" do
|
14
|
+
expect(subject).to set_view_local(:thing, 1)
|
15
|
+
expect(subject).to_not set_view_local(:thing, 2)
|
16
|
+
end
|
17
|
+
|
18
|
+
def assigns key
|
19
|
+
ctrl.instance_variable_get("@#{key}".to_sym)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RenderWithView do
|
4
|
+
|
5
|
+
describe "#render_with_view" do
|
6
|
+
it "calls render with template and assigned view" do
|
7
|
+
user = { id: 1 }
|
8
|
+
ctrl = FakeController.new
|
9
|
+
|
10
|
+
ctrl.render_with_view :index, user: user
|
11
|
+
|
12
|
+
tmpl, args = ctrl.calls.last
|
13
|
+
expect(tmpl).to eq :index
|
14
|
+
expect(args[:locals][:view].user).to eq(user)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defaults to action_name template" do
|
18
|
+
user = { id: 1 }
|
19
|
+
ctrl = FakeController.new
|
20
|
+
|
21
|
+
ctrl.render_with_view user: user
|
22
|
+
|
23
|
+
tmpl, * = ctrl.calls.last
|
24
|
+
expect(tmpl).to eq :new
|
25
|
+
end
|
26
|
+
|
27
|
+
it "saves to an instance var behind the scenes" do
|
28
|
+
user = { id: 1 }
|
29
|
+
ctrl = FakeController.new
|
30
|
+
|
31
|
+
ctrl.render_with_view :index, user: user
|
32
|
+
|
33
|
+
ivar = ctrl.instance_variable_get(:@__view__)
|
34
|
+
expect(ivar).to be_a RenderWithView::View
|
35
|
+
expect(ivar.user).to eq user
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_with_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
@@ -17,12 +17,20 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
20
22
|
- LICENSE
|
21
23
|
- README.md
|
24
|
+
- Rakefile
|
22
25
|
- lib/render_with_view.rb
|
23
26
|
- lib/render_with_view/half_open_struct.rb
|
24
27
|
- lib/render_with_view/rspec_matcher.rb
|
25
28
|
- lib/render_with_view/version.rb
|
29
|
+
- render_with_view.gemspec
|
30
|
+
- spec/render_with_view/half_open_struct_spec.rb
|
31
|
+
- spec/render_with_view/rspec_matcher_spec.rb
|
32
|
+
- spec/render_with_view_spec.rb
|
33
|
+
- spec/spec_helper.rb
|
26
34
|
homepage: https://github.com/mikker/render_with_view
|
27
35
|
licenses:
|
28
36
|
- MIT
|