better_helpers 0.1.2 → 0.1.3
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 +4 -4
- data/.gitignore +0 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +86 -0
- data/better_helpers.gemspec +1 -0
- data/lib/better_helpers.rb +4 -0
- data/lib/better_helpers/base.rb +1 -4
- data/lib/better_helpers/railtie.rb +11 -0
- data/lib/better_helpers/railties/filter.rb +17 -0
- data/lib/better_helpers/railties/request_context.rb +32 -0
- data/lib/better_helpers/version.rb +1 -1
- data/spec/better_helpers/base_spec.rb +26 -22
- data/spec/better_helpers/hash_hierarchy_to_class_spec.rb +42 -42
- data/spec/better_helpers/namespace_to_hash_spec.rb +7 -7
- data/spec/better_helpers/railties/filter_spec.rb +34 -0
- data/spec/better_helpers/railties/request_context_spec.rb +72 -0
- data/spec/fixtures/example_controller.rb +4 -0
- data/spec/spec_helper.rb +1 -1
- metadata +41 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b51c88122e5b9fc6c6d9d3b7dacd02b7c95a1dcb
|
4
|
+
data.tar.gz: 299dd39763854253db42df6c6f44b5c0c714cea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27262086f21e0283df1206f815988f6d35d2fdd10b4b51776a6d697d4cf3a8cd80375854115d8274348fa4d31b443a139d481dcc4de8ccb43c8ca8ef28d4b4db
|
7
|
+
data.tar.gz: 1a26b62dadc3d01ea99a14fd98d486842f3bbd9e6c11db61526f837edb874790f1d6a0c373513dafc6b3837b2809dd0a6aefdd3be64dec6b1a6c990c909d2e06
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
better_helpers (0.1.3)
|
5
|
+
railties (>= 3.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (4.2.1)
|
11
|
+
actionview (= 4.2.1)
|
12
|
+
activesupport (= 4.2.1)
|
13
|
+
rack (~> 1.6)
|
14
|
+
rack-test (~> 0.6.2)
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
17
|
+
actionview (4.2.1)
|
18
|
+
activesupport (= 4.2.1)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubis (~> 2.7.0)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
23
|
+
activesupport (4.2.1)
|
24
|
+
i18n (~> 0.7)
|
25
|
+
json (~> 1.7, >= 1.7.7)
|
26
|
+
minitest (~> 5.1)
|
27
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
28
|
+
tzinfo (~> 1.1)
|
29
|
+
builder (3.2.2)
|
30
|
+
byebug (5.0.0)
|
31
|
+
columnize (= 0.9.0)
|
32
|
+
columnize (0.9.0)
|
33
|
+
diff-lcs (1.2.5)
|
34
|
+
erubis (2.7.0)
|
35
|
+
i18n (0.7.0)
|
36
|
+
json (1.8.3)
|
37
|
+
loofah (2.0.2)
|
38
|
+
nokogiri (>= 1.5.9)
|
39
|
+
mini_portile (0.6.2)
|
40
|
+
minitest (5.7.0)
|
41
|
+
nokogiri (1.6.6.2)
|
42
|
+
mini_portile (~> 0.6.0)
|
43
|
+
rack (1.6.1)
|
44
|
+
rack-test (0.6.3)
|
45
|
+
rack (>= 1.0)
|
46
|
+
rails-deprecated_sanitizer (1.0.3)
|
47
|
+
activesupport (>= 4.2.0.alpha)
|
48
|
+
rails-dom-testing (1.0.6)
|
49
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
50
|
+
nokogiri (~> 1.6.0)
|
51
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
52
|
+
rails-html-sanitizer (1.0.2)
|
53
|
+
loofah (~> 2.0)
|
54
|
+
railties (4.2.1)
|
55
|
+
actionpack (= 4.2.1)
|
56
|
+
activesupport (= 4.2.1)
|
57
|
+
rake (>= 0.8.7)
|
58
|
+
thor (>= 0.18.1, < 2.0)
|
59
|
+
rake (10.4.2)
|
60
|
+
rspec (3.2.0)
|
61
|
+
rspec-core (~> 3.2.0)
|
62
|
+
rspec-expectations (~> 3.2.0)
|
63
|
+
rspec-mocks (~> 3.2.0)
|
64
|
+
rspec-core (3.2.3)
|
65
|
+
rspec-support (~> 3.2.0)
|
66
|
+
rspec-expectations (3.2.1)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.2.0)
|
69
|
+
rspec-mocks (3.2.1)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.2.0)
|
72
|
+
rspec-support (3.2.2)
|
73
|
+
thor (0.19.1)
|
74
|
+
thread_safe (0.3.5)
|
75
|
+
tzinfo (1.2.2)
|
76
|
+
thread_safe (~> 0.1)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
better_helpers!
|
83
|
+
bundler (~> 1.3)
|
84
|
+
byebug
|
85
|
+
rake
|
86
|
+
rspec
|
data/better_helpers.gemspec
CHANGED
data/lib/better_helpers.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require "active_support/core_ext/string/inflections"
|
2
|
+
require "active_support/core_ext/object/try"
|
2
3
|
require "action_view"
|
3
4
|
|
4
5
|
require "better_helpers/version"
|
5
6
|
require "better_helpers/base"
|
6
7
|
require "better_helpers/namespace_to_hash"
|
7
8
|
require "better_helpers/hash_hierarchy_to_class"
|
9
|
+
require "better_helpers/railties/filter"
|
10
|
+
require "better_helpers/railties/request_context"
|
11
|
+
require "better_helpers/railtie" if defined? ::Rails
|
8
12
|
|
9
13
|
module BetterHelpers
|
10
14
|
end
|
data/lib/better_helpers/base.rb
CHANGED
@@ -13,10 +13,7 @@ module BetterHelpers
|
|
13
13
|
def better_helpers namespace = nil, &block
|
14
14
|
helper_class = Class.new(&block)
|
15
15
|
helper_class.class_eval do
|
16
|
-
include
|
17
|
-
include ActionView::Context
|
18
|
-
extend ActionView::Helpers
|
19
|
-
extend ActionView::Context
|
16
|
+
include BetterHelpers::Railties::RequestContext
|
20
17
|
end
|
21
18
|
|
22
19
|
namespace ||= self.to_s.underscore
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BetterHelpers
|
2
|
+
module Railties
|
3
|
+
|
4
|
+
module Filter
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
prepend_before_filter :better_helpers_store_request
|
9
|
+
end
|
10
|
+
|
11
|
+
def better_helpers_store_request
|
12
|
+
Thread.current[RequestContext::NAME] = self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module BetterHelpers
|
2
|
+
module Railties
|
3
|
+
|
4
|
+
module RequestContext
|
5
|
+
NAME = :better_helpers_request_controller
|
6
|
+
|
7
|
+
def controller
|
8
|
+
Thread.current[NAME]
|
9
|
+
end
|
10
|
+
|
11
|
+
def view_context
|
12
|
+
controller.try(:view_context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing method, *args, &block
|
16
|
+
if view_context.respond_to?(method)
|
17
|
+
# Sends helper methods to the view context and cache the used
|
18
|
+
# methods to improve performance in the next calls
|
19
|
+
self.class.send(:define_method, method) do |*args, &block|
|
20
|
+
view_context.send(method, *args, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
self.send(method, *args, &block)
|
24
|
+
|
25
|
+
else
|
26
|
+
super(method, *args, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -17,43 +17,47 @@ describe BetterHelpers::Base do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should not conflict with old helpers" do
|
20
|
-
helpers.
|
21
|
-
helpers.global_helper_method.
|
20
|
+
expect(helpers).to respond_to :global_helper_method
|
21
|
+
expect(helpers.global_helper_method).to eql "test5"
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "when included" do
|
25
25
|
it "should include the class method 'better_helpers'" do
|
26
|
-
SomeHelper.
|
27
|
-
AnotherHelper.
|
26
|
+
expect(SomeHelper).to respond_to :better_helpers
|
27
|
+
expect(AnotherHelper).to respond_to :better_helpers
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "::better_helpers" do
|
32
|
+
it "includes the module 'BetterHelpers::Railties::RequestContext'" do
|
33
|
+
expect(helpers.another.class.ancestors).to include BetterHelpers::Railties::RequestContext
|
34
|
+
end
|
35
|
+
|
32
36
|
describe "without arguments" do
|
33
37
|
it "should include the helper methods into a 'namespace' with the underscore name of the module" do
|
34
|
-
helpers.
|
35
|
-
helpers.some_helper.helper_method.
|
38
|
+
expect(helpers).to respond_to SomeHelper.to_s.underscore
|
39
|
+
expect(helpers.some_helper.helper_method).to eql "test"
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
43
|
describe "with namespace argument" do
|
40
44
|
it "should include the helper methods into the defined 'namespace'" do
|
41
|
-
helpers.
|
42
|
-
helpers.another.helper_method.
|
45
|
+
expect(helpers).to respond_to :another
|
46
|
+
expect(helpers.another.helper_method).to eql "test2"
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
50
|
context "for helpers inside modules" do
|
47
51
|
it "should include as cascade methods" do
|
48
|
-
helpers.
|
49
|
-
helpers.inside_module_helper.
|
50
|
-
helpers.inside_module_helper.a.
|
51
|
-
helpers.inside_module_helper.a.b.helper_method.
|
52
|
+
expect(helpers).to respond_to :inside_module_helper
|
53
|
+
expect(helpers.inside_module_helper).to respond_to :a
|
54
|
+
expect(helpers.inside_module_helper.a).to respond_to :b
|
55
|
+
expect(helpers.inside_module_helper.a.b.helper_method).to eql "test3"
|
52
56
|
end
|
53
57
|
|
54
58
|
it "should allow namespace configuration" do
|
55
|
-
helpers.
|
56
|
-
helpers.custom_helper.helper_method.
|
59
|
+
expect(helpers).to respond_to :custom_helper
|
60
|
+
expect(helpers.custom_helper.helper_method).to eql "test4"
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -66,16 +70,16 @@ describe BetterHelpers::Base do
|
|
66
70
|
end
|
67
71
|
|
68
72
|
it "should include both helpers in the same module" do
|
69
|
-
helpers.
|
70
|
-
helpers.inside_module_helper.
|
71
|
-
helpers.inside_module_helper.a.
|
72
|
-
helpers.inside_module_helper.a.
|
73
|
+
expect(helpers).to respond_to :inside_module_helper
|
74
|
+
expect(helpers.inside_module_helper).to respond_to :a
|
75
|
+
expect(helpers.inside_module_helper.a).to respond_to :b
|
76
|
+
expect(helpers.inside_module_helper.a).to respond_to :c
|
73
77
|
|
74
|
-
helpers.inside_module_helper.a.b.
|
75
|
-
helpers.inside_module_helper.a.c.
|
78
|
+
expect(helpers.inside_module_helper.a.b).to respond_to :helper_method
|
79
|
+
expect(helpers.inside_module_helper.a.c).to respond_to :helper_method
|
76
80
|
|
77
|
-
helpers.inside_module_helper.a.b.helper_method.
|
78
|
-
helpers.inside_module_helper.a.c.helper_method.
|
81
|
+
expect(helpers.inside_module_helper.a.b.helper_method).to eql "test3"
|
82
|
+
expect(helpers.inside_module_helper.a.c.helper_method).to eql "test6"
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|
@@ -22,19 +22,19 @@ describe BetterHelpers::HashHierarchyToClass do
|
|
22
22
|
|
23
23
|
it "should include the methods into the parent class" do
|
24
24
|
apply
|
25
|
-
subject.
|
26
|
-
subject.
|
27
|
-
subject.
|
25
|
+
expect(subject).to respond_to :a
|
26
|
+
expect(subject).not_to respond_to :b
|
27
|
+
expect(subject).not_to respond_to :c
|
28
28
|
|
29
|
-
subject.a.
|
30
|
-
subject.a.
|
31
|
-
subject.a.
|
29
|
+
expect(subject.a).to respond_to :b
|
30
|
+
expect(subject.a).not_to respond_to :a
|
31
|
+
expect(subject.a).not_to respond_to :c
|
32
32
|
|
33
|
-
subject.a.b.
|
34
|
-
subject.a.b.
|
35
|
-
subject.a.b.
|
33
|
+
expect(subject.a.b).to respond_to :c
|
34
|
+
expect(subject.a.b).not_to respond_to :a
|
35
|
+
expect(subject.a.b).not_to respond_to :b
|
36
36
|
|
37
|
-
subject.a.b.c.
|
37
|
+
expect(subject.a.b.c).to eql 1
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should allow new instances with the same methods" do
|
@@ -43,19 +43,19 @@ describe BetterHelpers::HashHierarchyToClass do
|
|
43
43
|
instance3 = parent_class.new
|
44
44
|
|
45
45
|
[instance2, instance3].each do |instance|
|
46
|
-
instance.
|
47
|
-
instance.
|
48
|
-
instance.
|
46
|
+
expect(instance).to respond_to :a
|
47
|
+
expect(instance).not_to respond_to :b
|
48
|
+
expect(instance).not_to respond_to :c
|
49
49
|
|
50
|
-
instance.a.
|
51
|
-
instance.a.
|
52
|
-
instance.a.
|
50
|
+
expect(instance.a).to respond_to :b
|
51
|
+
expect(instance.a).not_to respond_to :a
|
52
|
+
expect(instance.a).not_to respond_to :c
|
53
53
|
|
54
|
-
instance.a.b.
|
55
|
-
instance.a.b.
|
56
|
-
instance.a.b.
|
54
|
+
expect(instance.a.b).to respond_to :c
|
55
|
+
expect(instance.a.b).not_to respond_to :a
|
56
|
+
expect(instance.a.b).not_to respond_to :b
|
57
57
|
|
58
|
-
instance.a.b.c.
|
58
|
+
expect(instance.a.b.c).to eql 1
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -75,29 +75,29 @@ describe BetterHelpers::HashHierarchyToClass do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should define the method in the parent class" do
|
78
|
-
subject.
|
79
|
-
subject.
|
80
|
-
subject.
|
81
|
-
subject.
|
78
|
+
expect(subject).to respond_to :a
|
79
|
+
expect(subject).not_to respond_to :b
|
80
|
+
expect(subject).not_to respond_to :c
|
81
|
+
expect(subject).not_to respond_to :d
|
82
82
|
|
83
|
-
subject.a.
|
84
|
-
subject.a.
|
85
|
-
subject.a.
|
86
|
-
subject.a.
|
83
|
+
expect(subject.a).to respond_to :b
|
84
|
+
expect(subject.a).to respond_to :c
|
85
|
+
expect(subject.a).not_to respond_to :a
|
86
|
+
expect(subject.a).not_to respond_to :d
|
87
87
|
|
88
|
-
subject.a.b.
|
89
|
-
subject.a.b.
|
90
|
-
subject.a.b.
|
91
|
-
subject.a.b.
|
88
|
+
expect(subject.a.b).to respond_to :d
|
89
|
+
expect(subject.a.b).not_to respond_to :a
|
90
|
+
expect(subject.a.b).not_to respond_to :b
|
91
|
+
expect(subject.a.b).not_to respond_to :c
|
92
92
|
|
93
|
-
subject.a.b.d.
|
93
|
+
expect(subject.a.b.d).to eql 1
|
94
94
|
|
95
|
-
subject.a.c.
|
96
|
-
subject.a.c.
|
97
|
-
subject.a.c.
|
98
|
-
subject.a.c.
|
95
|
+
expect(subject.a.c).to respond_to :d
|
96
|
+
expect(subject.a.c).not_to respond_to :a
|
97
|
+
expect(subject.a.c).not_to respond_to :b
|
98
|
+
expect(subject.a.c).not_to respond_to :c
|
99
99
|
|
100
|
-
subject.a.c.d.
|
100
|
+
expect(subject.a.c.d).to eql 2
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -111,7 +111,7 @@ describe BetterHelpers::HashHierarchyToClass do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should return the value" do
|
114
|
-
subject.
|
114
|
+
expect(subject).to eql 1
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -121,9 +121,9 @@ describe BetterHelpers::HashHierarchyToClass do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should return an instance of a callable object" do
|
124
|
-
subject.
|
125
|
-
subject.a.
|
126
|
-
subject.a.b.
|
124
|
+
expect(subject).to respond_to :a
|
125
|
+
expect(subject.a).to respond_to :b
|
126
|
+
expect(subject.a.b).to eql 1
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -11,15 +11,15 @@ describe BetterHelpers::NamespaceToHash do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should generate a nested hash resulting in the given object" do
|
14
|
-
subject.
|
15
|
-
subject.keys.
|
14
|
+
expect(subject).to be_an_instance_of Hash
|
15
|
+
expect(subject.keys).to eql ["a"]
|
16
16
|
|
17
|
-
subject["a"].
|
18
|
-
subject["a"].keys.
|
17
|
+
expect(subject["a"]).to be_an_instance_of Hash
|
18
|
+
expect(subject["a"].keys).to eql ["b"]
|
19
19
|
|
20
|
-
subject["a"]["b"].
|
21
|
-
subject["a"]["b"].keys.
|
22
|
-
subject["a"]["b"]["c"].
|
20
|
+
expect(subject["a"]["b"]).to be_an_instance_of Hash
|
21
|
+
expect(subject["a"]["b"].keys).to eql ["c"]
|
22
|
+
expect(subject["a"]["b"]["c"]).to be_an_instance_of String
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "fixtures/example_controller"
|
3
|
+
|
4
|
+
describe BetterHelpers::Railties::Filter do
|
5
|
+
|
6
|
+
let :include_module do
|
7
|
+
ExampleController.send :include, BetterHelpers::Railties::Filter
|
8
|
+
end
|
9
|
+
|
10
|
+
it "configures 'prepend_before_filter' with 'better_helpers_store_request'" do
|
11
|
+
expect(ExampleController).to receive(:prepend_before_filter).with(:better_helpers_store_request)
|
12
|
+
include_module
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#better_helpers_store_request" do
|
16
|
+
let :instance do
|
17
|
+
include_module
|
18
|
+
ExampleController.new
|
19
|
+
end
|
20
|
+
|
21
|
+
let :namespace do
|
22
|
+
BetterHelpers::Railties::RequestContext::NAME
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
instance.better_helpers_store_request
|
27
|
+
end
|
28
|
+
|
29
|
+
it "stores 'self' into 'Thread.current' under request context namespace" do
|
30
|
+
expect(Thread.current[namespace]).to eql instance
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BetterHelpers::Railties::RequestContext do
|
4
|
+
|
5
|
+
let :instance do
|
6
|
+
klass = Class.new
|
7
|
+
klass.class_eval do
|
8
|
+
include BetterHelpers::Railties::RequestContext
|
9
|
+
end
|
10
|
+
|
11
|
+
klass.new
|
12
|
+
end
|
13
|
+
|
14
|
+
let :view_context do
|
15
|
+
double("view context")
|
16
|
+
end
|
17
|
+
|
18
|
+
let :controller do
|
19
|
+
double("controller instance", view_context: view_context)
|
20
|
+
end
|
21
|
+
|
22
|
+
let :namespace do
|
23
|
+
BetterHelpers::Railties::RequestContext::NAME
|
24
|
+
end
|
25
|
+
|
26
|
+
before do
|
27
|
+
Thread.current[namespace] = controller
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#controller" do
|
31
|
+
it "returns the context of 'Thread.current'" do
|
32
|
+
expect(instance.controller).to eql Thread.current[namespace]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#view_context" do
|
37
|
+
it "returns the controller view_context" do
|
38
|
+
expect(instance.view_context).to eql instance.controller.view_context
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "when controller is nil" do
|
42
|
+
before do
|
43
|
+
expect(instance).to receive(:controller).and_return(nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns nil" do
|
47
|
+
expect(instance.view_context).to eql nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#method_missing" do
|
53
|
+
it "forwards the call to view_context" do
|
54
|
+
expect(view_context).to receive(:global_helper)
|
55
|
+
instance.global_helper
|
56
|
+
end
|
57
|
+
|
58
|
+
it "caches the method" do
|
59
|
+
expect(view_context).to receive(:global_helper)
|
60
|
+
expect(instance).to_not respond_to :global_helper
|
61
|
+
instance.global_helper
|
62
|
+
expect(instance).to respond_to :global_helper
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when view_context doesn't has the method" do
|
66
|
+
it "uses the default behavior" do
|
67
|
+
expect { instance.wrong_helper }.to raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ ENV['RACK_ENV'] = 'test'
|
|
2
2
|
|
3
3
|
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
4
4
|
|
5
|
+
require "byebug"
|
5
6
|
require "better_helpers"
|
6
7
|
|
7
8
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
@@ -11,7 +12,6 @@ require "better_helpers"
|
|
11
12
|
#
|
12
13
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
14
|
RSpec.configure do |config|
|
14
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
15
|
config.run_all_when_everything_filtered = true
|
16
16
|
config.filter_run :focus
|
17
17
|
|
metadata
CHANGED
@@ -1,69 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tulios
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description: It is a better way to organize and maintain your Rails helpers. It's
|
@@ -75,11 +89,12 @@ executables: []
|
|
75
89
|
extensions: []
|
76
90
|
extra_rdoc_files: []
|
77
91
|
files:
|
78
|
-
- .gitignore
|
79
|
-
- .rspec
|
80
|
-
- .ruby-gemset
|
81
|
-
- .ruby-version
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".ruby-gemset"
|
95
|
+
- ".ruby-version"
|
82
96
|
- Gemfile
|
97
|
+
- Gemfile.lock
|
83
98
|
- LICENSE.txt
|
84
99
|
- README.md
|
85
100
|
- Rakefile
|
@@ -88,11 +103,17 @@ files:
|
|
88
103
|
- lib/better_helpers/base.rb
|
89
104
|
- lib/better_helpers/hash_hierarchy_to_class.rb
|
90
105
|
- lib/better_helpers/namespace_to_hash.rb
|
106
|
+
- lib/better_helpers/railtie.rb
|
107
|
+
- lib/better_helpers/railties/filter.rb
|
108
|
+
- lib/better_helpers/railties/request_context.rb
|
91
109
|
- lib/better_helpers/version.rb
|
92
110
|
- spec/better_helpers/base_spec.rb
|
93
111
|
- spec/better_helpers/hash_hierarchy_to_class_spec.rb
|
94
112
|
- spec/better_helpers/namespace_to_hash_spec.rb
|
113
|
+
- spec/better_helpers/railties/filter_spec.rb
|
114
|
+
- spec/better_helpers/railties/request_context_spec.rb
|
95
115
|
- spec/fixtures/another_helper.rb
|
116
|
+
- spec/fixtures/example_controller.rb
|
96
117
|
- spec/fixtures/inside_module_custom_helper.rb
|
97
118
|
- spec/fixtures/inside_module_helper.rb
|
98
119
|
- spec/fixtures/some_helper.rb
|
@@ -107,17 +128,17 @@ require_paths:
|
|
107
128
|
- lib
|
108
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
130
|
requirements:
|
110
|
-
- -
|
131
|
+
- - ">="
|
111
132
|
- !ruby/object:Gem::Version
|
112
133
|
version: '0'
|
113
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
135
|
requirements:
|
115
|
-
- -
|
136
|
+
- - ">="
|
116
137
|
- !ruby/object:Gem::Version
|
117
138
|
version: '0'
|
118
139
|
requirements: []
|
119
140
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.4.6
|
121
142
|
signing_key:
|
122
143
|
specification_version: 4
|
123
144
|
summary: It is a better way to organize and maintain your Rails helpers
|
@@ -125,7 +146,10 @@ test_files:
|
|
125
146
|
- spec/better_helpers/base_spec.rb
|
126
147
|
- spec/better_helpers/hash_hierarchy_to_class_spec.rb
|
127
148
|
- spec/better_helpers/namespace_to_hash_spec.rb
|
149
|
+
- spec/better_helpers/railties/filter_spec.rb
|
150
|
+
- spec/better_helpers/railties/request_context_spec.rb
|
128
151
|
- spec/fixtures/another_helper.rb
|
152
|
+
- spec/fixtures/example_controller.rb
|
129
153
|
- spec/fixtures/inside_module_custom_helper.rb
|
130
154
|
- spec/fixtures/inside_module_helper.rb
|
131
155
|
- spec/fixtures/some_helper.rb
|