rao-view_helper 0.0.18.pre → 0.0.19.pre

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
  SHA256:
3
- metadata.gz: 380d55ed4b52a9fd8c9ffb1f843471a49a36b52939b0e417c70a87bad2cb3e15
4
- data.tar.gz: da6db7d823ef3117886cda2f19e0ca5d86c1b37cdf4691c3df1b8ef833dde6f5
3
+ metadata.gz: 8f41a651613804f334cc68670b5c5c89a9c63cdad0d85235774862a1bf0889d7
4
+ data.tar.gz: 26cb3a5fb539b9fa7a29d1f67e0f81db58c260878a98f3aaf85897d3e5543114
5
5
  SHA512:
6
- metadata.gz: e403c0e92e7a7927417eb3b49695ae4d023a270ea95bbec9bfe17696df32c694d502537c29f91ab5c40a5a2c6cfc783835056b32106914a980a8f6d255112590
7
- data.tar.gz: 47214dee741663de9c47a56cb0d9add9242e23727018fd6fe97cbc3d3649eac9b64f277660be665f432f113095f04be729d8a448c368e89a68b4fa8b84deba3f
6
+ metadata.gz: 69e90d4dca7a984e7892862ad92cfedcf08c1314ff9361158586d8a53e836826e6291e6cafbb7ec08237cc5deedab4404606f9ed4f07b8085325311a5903d488
7
+ data.tar.gz: c10022f62b93f6fdd62d87b2d278818f2c258edc8abb49469cd5a1c0107ef43e7429ff0e70ff6076a2aca479d7c81ca52ef93e6976e0c6e85ff67a82c6e35c92
@@ -28,6 +28,10 @@ module Rao
28
28
  def c
29
29
  @context
30
30
  end
31
+
32
+ def render(locals = {})
33
+ c.render partial: "/#{self.class.name.underscore}/#{caller_locations(1,1)[0].label}", locals: locals
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -13,10 +13,24 @@ module Rao
13
13
  #
14
14
  # Usage:
15
15
  #
16
- # # spec/view_helper/blorgh/application_view_helper_spec.rb
16
+ # # spec/view_helpers/blorgh/application_view_helper_spec.rb
17
17
  # require 'rails_helper'
18
18
  #
19
19
  # RSpec.describe Blorgh::ApplicationViewHelper, type: :view_helper do
20
+ # let(:posts) { create_list(:posts, 3) }
21
+ # let(:options) { {} }
22
+ # let(:args) { [posts, options] }
23
+ #
24
+ # # if your view_helper depends on other view helpers you can register
25
+ # # them by calling register_view_helper the same way you'd call
26
+ # # view_helper in a controller.
27
+ # before(:each) do
28
+ # register_view_helper Cmor::Core::MarkupViewHelper, as: :markup_helper
29
+ # end
30
+ #
31
+ # # if you need to change the default_url_options you may do so like this
32
+ # let(:default_url_options) { { host: 'example.org' } }
33
+ #
20
34
  # describe 'posts' do
21
35
  # it { expect(rendered).to have_xpath("//div[@id='blorgh-posts']") }
22
36
  # end
@@ -29,15 +43,33 @@ module Rao
29
43
  mod.let(:view) { ActionView::Base.new(view_paths, assigns) }
30
44
  mod.let(:view_helper) { described_class.new(view) }
31
45
  mod.let(:method_name) { |e| e.metadata[:example_group][:description].to_sym }
46
+ mod.let(:default_url_options) { { host: 'localhost:3000' } }
32
47
  mod.let(:rendered) {
33
48
  if respond_to?(:options)
34
49
  Capybara::Node::Simple.new(subject.send(method_name, options))
50
+ elsif respond_to?(:args)
51
+ Capybara::Node::Simple.new(subject.send(method_name, *args))
35
52
  else
36
53
  Capybara::Node::Simple.new(subject.send(method_name))
37
54
  end
38
55
  }
56
+
57
+ mod.before(:each) { view.class.send(:define_method, :main_app, -> { Rails.application.class.routes.url_helpers }) }
58
+ mod.around(:each) do |example|
59
+ original_default_url_options = Rails.application.routes.default_url_options
60
+ Rails.application.routes.default_url_options = default_url_options
61
+ example.run
62
+ Rails.application.routes.default_url_options = original_default_url_options
63
+ end
39
64
 
40
65
  mod.subject { view_helper }
66
+
67
+ mod.send(:define_method, :register_view_helper) do |klass, options = {}|
68
+ method_name = options.delete(:as) || klass.name.underscore.gsub('/', '_')
69
+ view.class.send(:define_method, method_name) do |context|
70
+ klass.new(context)
71
+ end
72
+ end
41
73
  end
42
74
  end
43
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rao-view_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18.pre
4
+ version: 0.0.19.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rao