render_with_view 0.1.2 → 0.2.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
- SHA1:
3
- metadata.gz: dd04d6b67b1beecdd49900563e12f702af15b8fa
4
- data.tar.gz: 94e175806972868258a5a8fc8dcd3a08d2177b3c
2
+ SHA256:
3
+ metadata.gz: 8aa151fcf7f21842f19aac1b46c4e94fa525a1ba00beff1f4034042153100faf
4
+ data.tar.gz: ae2a1259739e9bc8c2de8237c0631e2385ec7a3cbef82e4afbea99016e04345c
5
5
  SHA512:
6
- metadata.gz: 406d125e96f6caf8b639d00a4747a2d05e24ba89e008d37ed10e238051d320da22ff62cd36983beaee1ed968b6b64dec0d911a0becea67381f320072f8bedce8
7
- data.tar.gz: ed81fe1fd2d8431bf4013fdb782acc3c69cf35e05686b2e78bd66cd51226f302e43605a4aa2a5a5439f4a649223bfb7e0f837f5cce9ab6684dfc04a48b397bf3
6
+ metadata.gz: e864e6c20b78d8e6c181a52cd1b1d6daa0d5dd12df50a44422f6757f7be5d54df4598764d6dab9a3adf9ec49c22b8a22181f67fe1a4e71881a3c97e683b8845c
7
+ data.tar.gz: 2044c39043b71feb3a41239ac802bcdd21c73a9b100c1f02180a84b067047cd1644c9f1834fa91c42e2244afc0719a57c94a0cb0cd1843132d98949cd69a7935
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "02:00"
8
+ open-pull-requests-limit: 10
@@ -0,0 +1,17 @@
1
+ name: Tests
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest]
9
+ ruby: ["3.0", "3.1", "3.2"]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (2023-08-29)
4
+
5
+ Start of this document.
6
+
7
+ ### Changed:
8
+
9
+ - Use ActiveSupport::Concern instead of locals
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
- require 'bundler'
1
+ require "bundler"
2
+
2
3
  Bundler::GemHelper.install_tasks
3
4
 
4
- require 'rspec/core/rake_task'
5
+ require "rspec/core/rake_task"
6
+
5
7
  RSpec::Core::RakeTask.new(:spec) do |spec|
6
- spec.pattern = 'spec/**/*_spec.rb'
8
+ spec.pattern = "spec/**/*_spec.rb"
7
9
  end
8
- task :default => :spec
9
10
 
11
+ task(:default => :spec)
@@ -1,12 +1,12 @@
1
- RSpec::Matchers.define :set_view_local do |key, expected = nil|
1
+ RSpec::Matchers.define(:set_view_local) do |key, expected = nil|
2
2
  match do |block|
3
3
  block.call if block && block.is_a?(Proc)
4
4
 
5
- value = assigns('__view__').send(key.to_sym) rescue nil
5
+ value = assigns("__view__").send(key.to_sym) rescue nil
6
6
 
7
7
  return !!value unless expected
8
8
 
9
- expect(expected).to eq(value)
9
+ expect(expected).to(eq(value))
10
10
  end
11
11
 
12
12
  supports_block_expectations
@@ -1,3 +1,3 @@
1
1
  module RenderWithView
2
- VERSION = '0.1.2'
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,26 +1,36 @@
1
- require 'render_with_view/version'
2
- require 'render_with_view/half_open_struct'
1
+ require "active_support/concern"
2
+ require "render_with_view/version"
3
+ require "render_with_view/half_open_struct"
3
4
 
4
5
  module RenderWithView
5
- class View < HalfOpenStruct; end
6
-
7
- def self.included kls
8
- kls.class_eval do
9
- def render_with_view *args
10
- if !args.first.is_a?(Hash)
11
- tmpl = args.shift
12
- else
13
- tmpl = action_name
14
- end
15
- locals = args.shift
16
- opts = args.shift || {}
17
-
18
- # save to ivar for testing purposes
19
- @__view__ = View.new(locals)
20
-
21
- render tmpl, opts.merge(locals: { view: @__view__ })
6
+ extend ActiveSupport::Concern
7
+
8
+ class View < HalfOpenStruct
9
+ end
10
+
11
+ included do
12
+ helper_method :view
13
+
14
+ def view
15
+ raise ViewNotDefinedError, "View not defined" if !@__view__
16
+
17
+ @__view__
18
+ end
19
+
20
+ def render_with_view(*args)
21
+ if !args.first.is_a?(Hash)
22
+ tmpl = args.shift
23
+ else
24
+ tmpl = action_name
22
25
  end
26
+
27
+ view = args.shift
28
+ opts = args.shift || {}
29
+
30
+ # save to ivar for testing purposes
31
+ @__view__ = View.new(view)
32
+
33
+ render(tmpl, opts)
23
34
  end
24
35
  end
25
36
  end
26
-
@@ -2,15 +2,18 @@
2
2
  require File.expand_path("../lib/render_with_view/version", __FILE__)
3
3
 
4
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'
5
+ s.name = "render_with_view"
6
+ s.summary = "Be explicit about what you send to your Rails views"
7
7
  s.version = RenderWithView::VERSION
8
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'
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.add_dependency("rails")
15
+ s.add_development_dependency("rspec")
13
16
 
14
17
  s.files = `git ls-files`.split("\n")
15
- s.require_path = "lib"
18
+ s.require_path = "lib"
16
19
  end
@@ -1,13 +1,13 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module RenderWithView
4
4
  RSpec.describe HalfOpenStruct do
5
5
  it "can be initialized with a hash, and values read and written" do
6
6
  s = HalfOpenStruct.new(name: "Joe")
7
- expect(s.name).to eq "Joe"
7
+ expect(s.name).to eq("Joe")
8
8
 
9
9
  s.age = 42
10
- expect(s.age).to eq 42
10
+ expect(s.age).to eq(42)
11
11
  end
12
12
 
13
13
  it "raises trying to read an unknown value" do
@@ -16,7 +16,7 @@ module RenderWithView
16
16
  expect { s.age }.to raise_error("Unknown key: age")
17
17
 
18
18
  s.age = 42
19
- expect(s.age).to eq 42
19
+ expect(s.age).to eq(42)
20
20
  end
21
21
 
22
22
  it "raises for unknown methods" do
@@ -28,18 +28,18 @@ module RenderWithView
28
28
  # Considered an API like "s.age?" but that's ambiguous with undefined vs. falsy values.
29
29
  it "lets you query for values being defined" do
30
30
  s = HalfOpenStruct.new
31
- expect(s.include?(:age)).to be false
31
+ expect(s.include?(:age)).to be(false)
32
32
 
33
33
  s.age = 42
34
- expect(s.include?(:age)).to be true
34
+ expect(s.include?(:age)).to be(true)
35
35
  end
36
36
 
37
37
  it "lets you fetch values with a fallback" do
38
38
  s = HalfOpenStruct.new
39
- expect(s.fetch(:age, :fallback)).to eq :fallback
39
+ expect(s.fetch(:age, :fallback)).to eq(:fallback)
40
40
 
41
41
  s.age = 42
42
- expect(s.fetch(:age, :fallback)).to eq 42
42
+ expect(s.fetch(:age, :fallback)).to eq(42)
43
43
  end
44
44
  end
45
45
  end
@@ -1,21 +1,21 @@
1
- require 'spec_helper'
2
- require 'render_with_view/rspec_matcher'
1
+ require "spec_helper"
2
+ require "render_with_view/rspec_matcher"
3
3
 
4
- RSpec.describe 'RSpec matcher' do
4
+ RSpec.describe "RSpec matcher" do
5
5
  let(:ctrl) { FakeController.new }
6
- subject { ctrl.render_with_view :index, thing: 1 }
6
+ subject { ctrl.render_with_view(:index, thing: 1) }
7
7
 
8
8
  # short form
9
- it { should set_view_local :thing }
10
- it { should_not set_view_local :other_thing }
9
+ it { should(set_view_local(:thing)) }
10
+ it { should_not(set_view_local(:other_thing)) }
11
11
 
12
12
  # long form
13
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)
14
+ expect(subject).to(set_view_local(:thing, 1))
15
+ expect(subject).to_not(set_view_local(:thing, 2))
16
16
  end
17
17
 
18
- def assigns key
18
+ def assigns(key)
19
19
  ctrl.instance_variable_get("@#{key}".to_sym)
20
20
  end
21
21
  end
@@ -1,50 +1,48 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  RSpec.describe RenderWithView do
4
4
 
5
5
  describe "#render_with_view" do
6
6
  it "calls render with template and assigned view" do
7
- user = { id: 1 }
7
+ user = {id: 1}
8
8
  ctrl = FakeController.new
9
9
 
10
- ctrl.render_with_view :index, user: user
10
+ ctrl.render_with_view(:index, user: user)
11
11
 
12
12
  tmpl, args = ctrl.calls.last
13
- expect(tmpl).to eq :index
14
- expect(args[:locals][:view].user).to eq(user)
13
+ expect(tmpl).to(eq(:index))
15
14
  end
16
15
 
17
16
  it "defaults to action_name template" do
18
- user = { id: 1 }
17
+ user = {id: 1}
19
18
  ctrl = FakeController.new
20
19
 
21
- ctrl.render_with_view user: user
20
+ ctrl.render_with_view(user: user)
22
21
 
23
22
  tmpl, * = ctrl.calls.last
24
- expect(tmpl).to eq :new
23
+ expect(tmpl).to(eq(:new))
25
24
  end
26
25
 
27
26
  it "saves to an instance var behind the scenes" do
28
- user = { id: 1 }
27
+ user = {id: 1}
29
28
  ctrl = FakeController.new
30
29
 
31
- ctrl.render_with_view :index, user: user
30
+ ctrl.render_with_view(:index, user: user)
32
31
 
33
32
  ivar = ctrl.instance_variable_get(:@__view__)
34
- expect(ivar).to be_a RenderWithView::View
35
- expect(ivar.user).to eq user
33
+ expect(ivar).to(be_a(RenderWithView::View))
34
+ expect(ivar.user).to(eq(user))
36
35
  end
37
36
 
38
37
  it "includes options" do
39
- user = { id: 1 }
40
- opts = { flash: {notice: "YAS!"} }
38
+ user = {id: 1}
39
+ opts = {status: 401}
41
40
  ctrl = FakeController.new
42
41
 
43
42
  ctrl.render_with_view(:edit, {user: user}, opts)
44
43
  tmpl, opts = ctrl.calls.last
45
- expect(tmpl).to eq :edit
46
- expect(opts[:flash]).to eq({notice: "YAS!"})
44
+ expect(tmpl).to(eq(:edit))
45
+ expect(opts[:status]).to(eq(401))
47
46
  end
48
47
  end
49
-
50
48
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
- require 'rspec/core'
2
- require 'render_with_view'
1
+ require "rspec/core"
2
+ require "render_with_view"
3
3
 
4
4
  class FakeController
5
+ def self.helper_method(*args)
6
+ end
7
+
5
8
  include RenderWithView
6
9
 
7
10
  attr_reader :calls
metadata CHANGED
@@ -1,23 +1,54 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_with_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-15 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
14
42
  email:
15
43
  - mikkel@brnbw.com
16
44
  executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
48
+ - ".github/dependabot.yml"
49
+ - ".github/workflows/test.yml"
20
50
  - ".gitignore"
51
+ - CHANGELOG.md
21
52
  - Gemfile
22
53
  - LICENSE
23
54
  - README.md
@@ -35,7 +66,7 @@ homepage: https://github.com/mikker/render_with_view
35
66
  licenses:
36
67
  - MIT
37
68
  metadata: {}
38
- post_install_message:
69
+ post_install_message:
39
70
  rdoc_options: []
40
71
  require_paths:
41
72
  - lib
@@ -50,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
81
  - !ruby/object:Gem::Version
51
82
  version: '0'
52
83
  requirements: []
53
- rubyforge_project:
54
- rubygems_version: 2.5.1
55
- signing_key:
84
+ rubygems_version: 3.4.19
85
+ signing_key:
56
86
  specification_version: 4
57
87
  summary: Be explicit about what you send to your Rails views
58
88
  test_files: []