render_with_view 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16c75b8652b4d928f2c02d3c22fc6b0557f05720
4
- data.tar.gz: 946a91bd39ffc868a96eadd82a7277251e1113ba
3
+ metadata.gz: 635dffd60e128b0e6d0aff1fa43ca4b796bcab64
4
+ data.tar.gz: e5ac59a8114b559f1c55be13040f130cbaa7dc8a
5
5
  SHA512:
6
- metadata.gz: d3b8e0a484f0baf8578a86314c58ccc504660c1a98ac103e18f6998b87ab5af963b5279727dcbfa9da60f4f0b21f6dab1c35c1def29041c96848c5e120fc96ec
7
- data.tar.gz: 79aa31678bcfff82a4cd358dfdeec6ad3f918389b69e554c5d333c1d9eb0f2d87fa6f7ff1a8b7fbb401218c93261fb48099561b6ab3fac715647a4e1b6e4a957
6
+ metadata.gz: 19d89f2f02b1f757689b94700cdb2fc68dd73b0d8438e9729f0895fc82220ed5d142c4a2c1f2dfcd0459520afac1d218d2ccb6c77f0de994d0e449e3ebe4e17f
7
+ data.tar.gz: 667de2408b432bc7b47598d0b458428d297b2c2a50eb151caa732529006fcb5400ba267687a0af443bb0524e5fbd733a30594c88f239285f925c1320bb688fdf
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+ task :default => :spec
9
+
@@ -1,3 +1,4 @@
1
+ require 'render_with_view/version'
1
2
  require 'render_with_view/half_open_struct'
2
3
 
3
4
  module RenderWithView
@@ -1,3 +1,3 @@
1
1
  module RenderWithView
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -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
@@ -0,0 +1,16 @@
1
+ require 'rspec/core'
2
+ require 'render_with_view'
3
+
4
+ class FakeController
5
+ include RenderWithView
6
+
7
+ attr_reader :calls
8
+
9
+ def action_name
10
+ :new
11
+ end
12
+
13
+ def render(*args)
14
+ (@calls ||= []) << args
15
+ end
16
+ end
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.0
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