magicka 0.5.3 → 0.5.4

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: 790574b274384507133ba81bff57316fdee267695e6a86bbb36da2065d98f918
4
- data.tar.gz: ded516626da7b9825e1711aa4d299cd0388de7293776cc20c9facc607b4ba8ef
3
+ metadata.gz: 72a1f044386185ab6424ca7bee6714e104cc5e3187bf4ce0f789dda229e71f2c
4
+ data.tar.gz: 34ea858057a3b387a71d1eb1d9a25ac2265344e90d4a4e0b5b9ab5f5327dc399
5
5
  SHA512:
6
- metadata.gz: a2fb23dfa2dca070216bede19831ca54bc0c9ee1340418848e647512d4ec7668ee97b0015aa8d7d3b85e6014883e263107ce8360efed4286342e714f502d93ce
7
- data.tar.gz: 6e165bd37c83eb5d3c0c760164f2f93e9d51d05f284621960012e24b81d5b7779140cca6f1d47128bd24a4545201e77becd489fa20d9e0ac6ba816cd01dc8fdf
6
+ metadata.gz: 618d045f43772a81df679643ffcf7999f2a05ca424d0d2fe5e30ee82a0a96801cfe5c6b2598b8dbd9efb8bb2ff5552a7d61a1d8b5555e2f6732c4106a35e4d0f
7
+ data.tar.gz: 8830926f9724a6ec3a516a222348be09f959059aae45311f2ae567f591c0d41a0e921c49a9fe71e6f708395c5739e6899d87e3873adebc120a629babed97edb0
@@ -32,7 +32,7 @@ RSpec/MultipleExpectations:
32
32
  - 'spec/integration/readme/**/*_spec.rb'
33
33
 
34
34
  RSpec/NestedGroups:
35
- Max: 4
35
+ Max: 5
36
36
  Exclude:
37
37
  - 'spec/integration/yard/**/*.rb'
38
38
 
data/README.md CHANGED
@@ -11,7 +11,7 @@ Magicka
11
11
 
12
12
  Yard Documentation
13
13
  -------------------
14
- [https://www.rubydoc.info/gems/magicka/0.5.3](https://www.rubydoc.info/gems/magicka/0.5.3)
14
+ [https://www.rubydoc.info/gems/magicka/0.5.4](https://www.rubydoc.info/gems/magicka/0.5.4)
15
15
 
16
16
  Installation
17
17
  ---------------
@@ -1,6 +1,5 @@
1
1
  ignore:
2
2
  - lib/magicka/version.rb
3
3
  - lib/magicka.rb
4
- - lib/magicka/aggregator.rb
5
4
  - lib/magicka/aggregator/method_builder.rb
6
5
  - lib/magicka/helper.rb
@@ -1,4 +1,4 @@
1
- threshold: 84.2
1
+ threshold: 84.1
2
2
  require_exact_threshold: false
3
3
  rules:
4
4
  ApiTag::Presence:
@@ -8,9 +8,9 @@ module Magicka
8
8
  autoload :MethodBuilder, 'magicka/aggregator/method_builder'
9
9
 
10
10
  class << self
11
- def with_element(element_class, method_name = nil)
11
+ def with_element(element_class, method_name = nil, template: nil)
12
12
  MethodBuilder
13
- .new(self, element_class, method_name)
13
+ .new(self, element_class, method_name, template: template)
14
14
  .prepare
15
15
  .build
16
16
  end
@@ -6,19 +6,23 @@ module Magicka
6
6
  #
7
7
  # Class responsible for building an {Aggregator} method
8
8
  class MethodBuilder < Sinclair
9
- def initialize(klass, element_class, method_name = nil)
9
+ def initialize(klass, element_class, method_name = nil, template: nil)
10
10
  super(klass)
11
11
 
12
12
  @element_class = element_class
13
13
  @method_name = method_name
14
+ @template = template
14
15
  end
15
16
 
16
17
  def prepare
17
18
  element_klass = element_class
19
+ template_file = template
18
20
 
19
21
  add_method(method_name) do |field, model: self.model, **args|
20
22
  element_klass.render(
21
- renderer: renderer, field: field, model: model, **args
23
+ renderer: renderer, field: field,
24
+ model: model, template: template_file,
25
+ **args
22
26
  )
23
27
  end
24
28
 
@@ -27,7 +31,7 @@ module Magicka
27
31
 
28
32
  private
29
33
 
30
- attr_reader :element_class
34
+ attr_reader :element_class, :template
31
35
 
32
36
  def method_name
33
37
  @method_name ||= element_class
@@ -77,8 +77,11 @@ module Magicka
77
77
  #
78
78
  # @return [String]
79
79
  def template
80
- self.class.name.underscore
81
- .gsub(%r{^.*/}, "#{template_folder}/")
80
+ @template ||= self
81
+ .class
82
+ .name
83
+ .underscore
84
+ .gsub(%r{^.*/}, "#{template_folder}/")
82
85
  end
83
86
  end
84
87
  end
@@ -14,7 +14,7 @@ module Magicka
14
14
  #
15
15
  # @return [Array<Sinclair::MethodDefinition>]
16
16
  def add_template(template)
17
- add_method(:template) do
17
+ add_method(:template, cached: true) do
18
18
  template
19
19
  end
20
20
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magicka
4
- VERSION = '0.5.3'
4
+ VERSION = '0.5.4'
5
5
  end
@@ -0,0 +1,209 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Aggregator do
6
+ subject(:aggregator) { aggregator_class.new(renderer, model) }
7
+
8
+ let(:aggregator_class) { Class.new(described_class) }
9
+ let(:model) { :my_model }
10
+ let(:renderer) { instance_double('renderer') }
11
+ let(:template) { 'templates/forms/input' }
12
+ let(:locals) { {} }
13
+
14
+ describe '.with_element' do
15
+ context 'when seeting element class only' do
16
+ it do
17
+ expect { aggregator_class.with_element(Magicka::Input) }
18
+ .to add_method(:input)
19
+ .to(aggregator)
20
+ end
21
+
22
+ context 'when built method is called' do
23
+ let(:template) { 'templates/forms/input' }
24
+ let(:field) { :field }
25
+ let(:label) { 'Label' }
26
+ let(:placeholder) { 'Value' }
27
+
28
+ let(:locals) do
29
+ {
30
+ field: field,
31
+ label: label,
32
+ ng_errors: 'my_model.errors.field',
33
+ ng_model: 'my_model.field',
34
+ placeholder: placeholder
35
+ }
36
+ end
37
+
38
+ let(:arguments) do
39
+ {
40
+ label: label,
41
+ placeholder: placeholder
42
+ }
43
+ end
44
+
45
+ before do
46
+ aggregator_class.with_element(Magicka::Input)
47
+
48
+ allow(renderer)
49
+ .to receive(:render)
50
+ .with(partial: template, locals: locals)
51
+ end
52
+
53
+ it 'renders an input' do
54
+ aggregator.input(field, arguments)
55
+
56
+ expect(renderer).to have_received(:render)
57
+ end
58
+
59
+ context 'when passing a custom model' do
60
+ let(:locals) do
61
+ {
62
+ field: field,
63
+ label: label,
64
+ ng_errors: 'my_custom_model.errors.field',
65
+ ng_model: 'my_custom_model.field',
66
+ placeholder: placeholder
67
+ }
68
+ end
69
+
70
+ it 'renders an input' do
71
+ aggregator.input(field, model: 'my_custom_model', **arguments)
72
+
73
+ expect(renderer).to have_received(:render)
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'when seeting element class and method' do
80
+ it do
81
+ expect { aggregator_class.with_element(Magicka::Input, :my_input) }
82
+ .to add_method(:my_input)
83
+ .to(aggregator)
84
+ end
85
+
86
+ context 'when built method is called' do
87
+ let(:template) { 'templates/forms/input' }
88
+ let(:field) { :field }
89
+ let(:label) { 'Label' }
90
+ let(:placeholder) { 'Value' }
91
+
92
+ let(:locals) do
93
+ {
94
+ field: field,
95
+ label: label,
96
+ ng_errors: 'my_model.errors.field',
97
+ ng_model: 'my_model.field',
98
+ placeholder: placeholder
99
+ }
100
+ end
101
+
102
+ let(:arguments) do
103
+ {
104
+ label: label,
105
+ placeholder: placeholder
106
+ }
107
+ end
108
+
109
+ before do
110
+ aggregator_class.with_element(Magicka::Input, :my_input)
111
+
112
+ allow(renderer)
113
+ .to receive(:render)
114
+ .with(partial: template, locals: locals)
115
+ end
116
+
117
+ it 'renders an input' do
118
+ aggregator.my_input(field, arguments)
119
+
120
+ expect(renderer).to have_received(:render)
121
+ end
122
+
123
+ context 'when passing a custom model' do
124
+ let(:locals) do
125
+ {
126
+ field: field,
127
+ label: label,
128
+ ng_errors: 'my_custom_model.errors.field',
129
+ ng_model: 'my_custom_model.field',
130
+ placeholder: placeholder
131
+ }
132
+ end
133
+
134
+ it 'renders an input' do
135
+ aggregator.my_input(field, model: 'my_custom_model', **arguments)
136
+
137
+ expect(renderer).to have_received(:render)
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'when seeting element class and template' do
144
+ it do
145
+ expect do
146
+ aggregator_class.with_element(Magicka::Input, template: template)
147
+ end
148
+ .to add_method(:input)
149
+ .to(aggregator)
150
+ end
151
+
152
+ context 'when built method is called' do
153
+ let(:template) { 'my_templates/my_input' }
154
+ let(:field) { :field }
155
+ let(:label) { 'Label' }
156
+ let(:placeholder) { 'Value' }
157
+
158
+ let(:locals) do
159
+ {
160
+ field: field,
161
+ label: label,
162
+ ng_errors: 'my_model.errors.field',
163
+ ng_model: 'my_model.field',
164
+ placeholder: placeholder
165
+ }
166
+ end
167
+
168
+ let(:arguments) do
169
+ {
170
+ label: label,
171
+ placeholder: placeholder
172
+ }
173
+ end
174
+
175
+ before do
176
+ aggregator_class.with_element(Magicka::Input, template: template)
177
+
178
+ allow(renderer)
179
+ .to receive(:render)
180
+ .with(partial: template, locals: locals)
181
+ end
182
+
183
+ it 'renders an input' do
184
+ aggregator.input(field, arguments)
185
+
186
+ expect(renderer).to have_received(:render)
187
+ end
188
+
189
+ context 'when passing a custom model' do
190
+ let(:locals) do
191
+ {
192
+ field: field,
193
+ label: label,
194
+ ng_errors: 'my_custom_model.errors.field',
195
+ ng_model: 'my_custom_model.field',
196
+ placeholder: placeholder
197
+ }
198
+ end
199
+
200
+ it 'renders an input' do
201
+ aggregator.input(field, model: 'my_custom_model', **arguments)
202
+
203
+ expect(renderer).to have_received(:render)
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
@@ -82,5 +82,46 @@ describe Magicka::Element do
82
82
  expect(renderer).to have_received(:render)
83
83
  end
84
84
  end
85
+
86
+ context 'when class has a template but is initialized with template' do
87
+ subject(:element) do
88
+ klass.new(renderer: renderer, template: custom_template)
89
+ end
90
+
91
+ let(:custom_template) { 'custom_folder/custom_template' }
92
+ let(:expected_template) { custom_template }
93
+
94
+ before do
95
+ klass.template(template)
96
+ end
97
+
98
+ it do
99
+ element.render
100
+
101
+ expect(renderer).to have_received(:render)
102
+ end
103
+ end
104
+
105
+ context 'when class has folder but is initialized with template' do
106
+ subject(:element) do
107
+ klass.new(renderer: renderer, template: custom_template)
108
+ end
109
+
110
+ let(:custom_template) { 'custom_folder/custom_template' }
111
+ let(:expected_template) { custom_template }
112
+
113
+ before do
114
+ klass.template_folder(folder)
115
+
116
+ method_builder.add_class_method(:name) { 'Magicka::MyElement' }
117
+ method_builder.build
118
+ end
119
+
120
+ it do
121
+ element.render
122
+
123
+ expect(renderer).to have_received(:render)
124
+ end
125
+ end
85
126
  end
86
127
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magicka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-10 00:00:00.000000000 Z
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -474,6 +474,7 @@ files:
474
474
  - spec/dummy/storage/.keep
475
475
  - spec/integration/readme/.keep
476
476
  - spec/integration/yard/.keep
477
+ - spec/lib/magicka/aggregator_spec.rb
477
478
  - spec/lib/magicka/button_spec.rb
478
479
  - spec/lib/magicka/display_spec.rb
479
480
  - spec/lib/magicka/element/class_methods_spec.rb