magicka 0.0.1 → 0.3.1

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: 6013fd94f8df1865e13bd0f17ddfd37b9605fb6cb72eebb14d7fa6a4761f48fd
4
- data.tar.gz: 4ae9c53984064068371fc060aaf178a34f772940908619d4937fc4bf6345a345
3
+ metadata.gz: 7939778de2faac419e42a17986de873d7cbefa0b65531dcc968f697411e0ee7a
4
+ data.tar.gz: 831909938f84d296ba8706893b13c5ef7bf9f5b16e2d57cb10986e83151a2ed3
5
5
  SHA512:
6
- metadata.gz: 2bdddadc15edd651be2484b29072e04b3b717d1cd45741996a3426a069bb5e6980fd42bf34d2d813b675d392d96f1aab278a87484f82488a7255bb4414ee350e
7
- data.tar.gz: '0783b6e54e90f43e71cf6d361ee34b9ae3bb4179f87b48f96e1a47c47ae72a2e4e8fa92d2e0f5870b2649905208e1bfa3fc6efbca7e24e40b260efdc3f05c7cc'
6
+ metadata.gz: 74b61fb09691f38d280b08adde917d838866b918f23d4b9a530bf0f43cd22d8c963980bd5e02de23b89e601bbb708fd374da6e5285e7507d33e1b319fe9937a7
7
+ data.tar.gz: 8a263ca1eb2a0fc180e4fdc9eff054aede6452e19819d788b1e6c3f203875104ea177c1f2b8d38b14d5909d506528fb2a621fcdb4aafe9ab7ff49513bac3509e
data/Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
1
  FROM darthjee/scripts:0.1.8 as scripts
2
2
 
3
- FROM darthjee/rails_gems:0.5.4 as base
3
+ FROM darthjee/rails_gems:0.6.0 as base
4
4
 
5
5
  COPY --chown=app:app ./ /home/app/app/
6
6
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Jace
1
+ Magicka
2
2
  ====
3
3
  [![Code Climate](https://codeclimate.com/github/darthjee/magicka/badges/gpa.svg)](https://codeclimate.com/github/darthjee/magicka)
4
4
  [![Test Coverage](https://codeclimate.com/github/darthjee/magicka/badges/coverage.svg)](https://codeclimate.com/github/darthjee/magicka/coverage)
@@ -11,7 +11,7 @@ Jace
11
11
 
12
12
  Yard Documentation
13
13
  -------------------
14
- [https://www.rubydoc.info/gems/magicka/0.0.1](https://www.rubydoc.info/gems/magicka/0.0.1)
14
+ [https://www.rubydoc.info/gems/magicka/0.3.1](https://www.rubydoc.info/gems/magicka/0.3.1)
15
15
 
16
16
  Installation
17
17
  ---------------
@@ -1,2 +1,3 @@
1
1
  ignore:
2
2
  - lib/magicka/version.rb
3
+ - lib/magicka.rb
@@ -1,4 +1,4 @@
1
- threshold: 100
1
+ threshold: 92.2
2
2
  require_exact_threshold: false
3
3
  rules:
4
4
  ApiTag::Presence:
@@ -21,7 +21,8 @@ rules:
21
21
  exclude: []
22
22
  Summary::Presence:
23
23
  enabled: true
24
- exclude: []
24
+ exclude:
25
+ - Magicka::Element#initialize
25
26
  Summary::Length:
26
27
  enabled: true
27
28
  exclude: []
@@ -2,6 +2,19 @@
2
2
 
3
3
  # @api public
4
4
  # @author darthjee
5
- class Magicka
6
- autoload :VERSION, 'magicka/version'
5
+
6
+ require 'sinclair'
7
+
8
+ # @api public
9
+ # @author Darthjee
10
+ #
11
+ # module holding herlper to render inputs
12
+ module Magicka
13
+ autoload :VERSION, 'magicka/version'
14
+ autoload :Button, 'magicka/button'
15
+ autoload :Element, 'magicka/element'
16
+ autoload :FormElement, 'magicka/form_element'
17
+ autoload :Input, 'magicka/input'
18
+ autoload :MethodBuilder, 'magicka/method_builder'
19
+ autoload :Select, 'magicka/select'
7
20
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # Button element representing an HTML +<button/>+
5
+ class Button < Element
6
+ with_attribute_locals :ng_click, :ng_disabled, :classes, :text
7
+ template_folder 'templates/forms'
8
+ end
9
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # @api public
5
+ #
6
+ # Base class for element rendering
7
+ class Element < Sinclair::Options
8
+ autoload :ClassMethods, 'magicka/element/class_methods'
9
+
10
+ skip_validation
11
+
12
+ class << self
13
+ # @api public
14
+ # @!visibility public
15
+ #
16
+ # Add available options
17
+ #
18
+ # @return [Array<Sinclair::MethodDefinition>]
19
+ alias with_attributes with_options
20
+
21
+ include ClassMethods
22
+ end
23
+
24
+ # @method with_attributes
25
+ # @api public
26
+ # @!visibility public
27
+ #
28
+ # Adds attribute
29
+ #
30
+ # This will affect initialization and add readers
31
+ #
32
+ # @return [Array]
33
+
34
+ # Render element HTML
35
+ def render
36
+ renderer.render partial: template, locals: locals
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :renderer
42
+ # @api private
43
+ # @private
44
+ # @method renderer
45
+ #
46
+ # Object responsible for rendering the HTML
47
+
48
+ # @api private
49
+ # @private
50
+ #
51
+ # @param (see .render)
52
+ def initialize(renderer:, **args)
53
+ @renderer = renderer
54
+ super(**args)
55
+ end
56
+
57
+ # @api private
58
+ # @private
59
+ #
60
+ # Returns hash of local variables
61
+ #
62
+ # Local variablees will be available when rendering
63
+ # the template
64
+ #
65
+ # @return [Hash]
66
+ def locals
67
+ self.class.locals.inject({}) do |hash, attribute|
68
+ hash.merge!(attribute => send(attribute))
69
+ end
70
+ end
71
+
72
+ # @api public
73
+ # @private
74
+ #
75
+ # Returns template file location
76
+ #
77
+ # @return [String]
78
+ def template
79
+ self.class.name.underscore
80
+ .gsub(%r{^.*/}, "#{template_folder}/")
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ class Element < Sinclair::Options
5
+ # @api public
6
+ #
7
+ # Class methods used for metaprograming of elements
8
+ module ClassMethods
9
+ # render template using the given prameters
10
+ #
11
+ # @param renderer [Object] object responsible for rendering
12
+ # the HTML
13
+ # @param args [Hash] Extra options
14
+ def render(renderer:, **args)
15
+ new(renderer: renderer, **args).render
16
+ end
17
+
18
+ # list of attributes to be used when rendering
19
+ #
20
+ # @return [Set<Symbol>]
21
+ def locals
22
+ @locals ||= superclass.try(:locals)&.dup || Set.new([])
23
+ end
24
+
25
+ # Sets template for element type
26
+ #
27
+ # @return [Array<Sinclair::MethodDefinition>]
28
+ def template(template)
29
+ MethodBuilder
30
+ .new(self)
31
+ .add_template(template)
32
+ end
33
+
34
+ # Sets template folder for element type
35
+ #
36
+ # @return [Array<Sinclair::MethodDefinition>]
37
+ def template_folder(folder)
38
+ MethodBuilder
39
+ .new(self)
40
+ .add_template_folder(folder)
41
+ end
42
+
43
+ private
44
+
45
+ # @api public
46
+ # @!visibility public
47
+ #
48
+ # Add an attribute to locals when rendereing
49
+ #
50
+ # the attribute will be a call to the a method
51
+ # with same name
52
+ #
53
+ # @return [Set<Symbol>]
54
+ def with_locals(*args)
55
+ locals.merge(args)
56
+ end
57
+
58
+ # @api public
59
+ # @!visibility public
60
+ #
61
+ # Adds attribute and locals
62
+ #
63
+ # @return [Array]
64
+ def with_attribute_locals(*args)
65
+ with_locals(*args)
66
+ with_attributes(*args)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # @api public
5
+ #
6
+ # Basic class for elements for forms
7
+ class FormElement < Element
8
+ with_attribute_locals :field, :label
9
+ with_attributes :model
10
+ with_locals :ng_errors, :ng_model
11
+
12
+ template_folder 'templates/forms'
13
+
14
+ private
15
+
16
+ # @api private
17
+ # @private
18
+ #
19
+ # Label to be shon near the input
20
+ #
21
+ # when no label is provided, the name of
22
+ # the field is used
23
+ #
24
+ # @return [String]
25
+ def label
26
+ @label ||= field.to_s.capitalize.gsub(/_/, ' ')
27
+ end
28
+
29
+ # @api private
30
+ # @private
31
+ #
32
+ # ng model to be represented with the input
33
+ #
34
+ # @return [String]
35
+ def ng_model
36
+ [model, field].join('.')
37
+ end
38
+
39
+ # @api private
40
+ # @private
41
+ #
42
+ # ng errors to be exposed with the input
43
+ #
44
+ # @return [String]
45
+ def ng_errors
46
+ [model, :errors, field].join('.')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # Input element representing an HTML +<input/>+
5
+ class Input < FormElement
6
+ with_attribute_locals :placeholder
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # @api private
5
+ #
6
+ # class responsible for building methods on {Magicka::Element}
7
+ class MethodBuilder < Sinclair
8
+ # adds a mehtod +#template+
9
+ #
10
+ # The method will always return the template given in the params
11
+ #
12
+ # @param template [String] path to template file
13
+ #
14
+ # @return [Array<Sinclair::MethodDefinition>]
15
+ def add_template(template)
16
+ add_method(:template) do
17
+ template
18
+ end
19
+
20
+ build
21
+ end
22
+
23
+ # adds a mehtod +#template_folder+
24
+ #
25
+ # The method will always return the template folder given in the params
26
+ #
27
+ # @param template_folder [String] path to template folder
28
+ #
29
+ # @return [Array<Sinclair::MethodDefinition>]
30
+ def add_template_folder(folder)
31
+ add_method(:template_folder) do
32
+ folder
33
+ end
34
+
35
+ build
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magicka
4
+ # Select element representing an HTML +<select/>+
5
+ class Select < FormElement
6
+ with_attribute_locals :options
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Magicka
4
- VERSION = '0.0.1'
3
+ module Magicka
4
+ VERSION = '0.3.1'
5
5
  end
@@ -19,17 +19,17 @@ Gem::Specification.new do |gem|
19
19
  gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
20
20
  gem.require_paths = ['lib']
21
21
 
22
- gem.add_runtime_dependency 'activesupport', '~> 5.2.4.2'
23
- gem.add_runtime_dependency 'sinclair', '>= 1.6.6'
22
+ gem.add_runtime_dependency 'activesupport', '~> 5.2.4.3'
23
+ gem.add_runtime_dependency 'sinclair', '>= 1.6.7'
24
24
 
25
- gem.add_development_dependency 'actionpack', '5.2.4.2'
26
- gem.add_development_dependency 'activerecord', '5.2.4.2'
25
+ gem.add_development_dependency 'actionpack', '5.2.4.3'
26
+ gem.add_development_dependency 'activerecord', '5.2.4.3'
27
27
  gem.add_development_dependency 'bundler', '1.16.1'
28
28
  gem.add_development_dependency 'factory_bot', '5.2.0'
29
29
  gem.add_development_dependency 'nokogiri', '1.10.9'
30
30
  gem.add_development_dependency 'pry', '0.12.2'
31
31
  gem.add_development_dependency 'pry-nav', '0.3.0'
32
- gem.add_development_dependency 'rails', '5.2.4.2'
32
+ gem.add_development_dependency 'rails', '5.2.4.3'
33
33
  gem.add_development_dependency 'rails-controller-testing', '1.0.4'
34
34
  gem.add_development_dependency 'rake', '13.0.1'
35
35
  gem.add_development_dependency 'reek', '5.6.0'
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Button do
6
+ let(:renderer) { instance_double('renderer') }
7
+ let(:template) { 'templates/forms/button' }
8
+
9
+ let(:ng_click) { 'controler.click()' }
10
+ let(:ng_disabled) { 'false' }
11
+ let(:classes) { 'custom class' }
12
+ let(:text) { 'Click' }
13
+
14
+ let(:locals) do
15
+ {
16
+ ng_click: ng_click,
17
+ ng_disabled: ng_disabled,
18
+ classes: classes,
19
+ text: text
20
+ }
21
+ end
22
+
23
+ describe '.render' do
24
+ let(:arguments) do
25
+ {
26
+ renderer: renderer,
27
+ ng_click: ng_click,
28
+ ng_disabled: ng_disabled,
29
+ classes: classes,
30
+ text: text
31
+ }
32
+ end
33
+
34
+ before do
35
+ allow(renderer)
36
+ .to receive(:render)
37
+ .with(partial: template, locals: locals)
38
+ end
39
+
40
+ it do
41
+ described_class.render(arguments)
42
+
43
+ expect(renderer).to have_received(:render)
44
+ end
45
+
46
+ context 'when called with extra params' do
47
+ it do
48
+ described_class.render(name: 'Name', **arguments)
49
+
50
+ expect(renderer).to have_received(:render)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Element::ClassMethods do
6
+ subject(:element) { klass.new(renderer: renderer) }
7
+
8
+ let(:klass) do
9
+ Class.new(Magicka::Element)
10
+ end
11
+
12
+ let(:renderer) { instance_double('renderer') }
13
+ let(:template) { 'templates/forms/element' }
14
+ let(:locals) { {} }
15
+
16
+ describe '.with_attributes' do
17
+ it do
18
+ expect { klass.send(:with_attributes, :field) }
19
+ .to add_method(:field)
20
+ .to(klass)
21
+ end
22
+ end
23
+
24
+ describe '.template' do
25
+ it do
26
+ expect { klass.template(template) }
27
+ .to add_method(:template)
28
+ .to(klass)
29
+ end
30
+
31
+ context 'when method is build as requested' do
32
+ before { klass.template(template) }
33
+
34
+ it 'returns the defined template when method is called' do
35
+ expect(element.template).to eq(template)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '.template_folder' do
41
+ let(:folder) { 'templates/forms' }
42
+
43
+ it do
44
+ expect { klass.template_folder(folder) }
45
+ .to add_method(:template_folder)
46
+ .to(klass)
47
+ end
48
+
49
+ context 'when method is build as requested' do
50
+ before { klass.template_folder(folder) }
51
+
52
+ it 'returns the defined template when method is called' do
53
+ expect(element.template_folder).to eq(folder)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '.render' do
59
+ before do
60
+ klass.template(template)
61
+
62
+ allow(renderer)
63
+ .to receive(:render)
64
+ .with(partial: template, locals: locals)
65
+ end
66
+
67
+ it do
68
+ klass.render(renderer: renderer)
69
+
70
+ expect(renderer).to have_received(:render)
71
+ end
72
+
73
+ context 'when called with extra params' do
74
+ it do
75
+ klass.render(renderer: renderer, name: 'Name')
76
+
77
+ expect(renderer).to have_received(:render)
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '.locals' do
83
+ it { expect(Magicka::Element.locals).to eq(Set.new([])) }
84
+
85
+ context 'when calling on a subclass' do
86
+ it { expect(klass.locals).to eq(Set.new([])) }
87
+ end
88
+
89
+ context 'when called on subclass' do
90
+ let(:subclass) { Class.new(klass) }
91
+
92
+ before { klass.send(:with_locals, :field, :model) }
93
+
94
+ it { expect(subclass.locals).to eq(Set.new(%i[field model])) }
95
+ end
96
+ end
97
+
98
+ describe 'with_locals' do
99
+ it do
100
+ expect { klass.send(:with_locals, :field, :model) }
101
+ .to change(klass, :locals)
102
+ .from([])
103
+ .to(%i[field model])
104
+ end
105
+
106
+ it do
107
+ expect { klass.send(:with_locals, :field, :model) }
108
+ .not_to change(Magicka::Element, :locals)
109
+ end
110
+
111
+ it do
112
+ expect { klass.send(:with_locals, :field) }
113
+ .not_to add_method(:field)
114
+ .to(klass)
115
+ end
116
+
117
+ context 'when called on subclass' do
118
+ let(:subclass) { Class.new(klass) }
119
+
120
+ before { klass.send(:with_locals, :field, :model) }
121
+
122
+ it do
123
+ expect { subclass.send(:with_locals, :error) }
124
+ .to change(subclass, :locals)
125
+ .from(%i[field model])
126
+ .to(%i[field model error])
127
+ end
128
+
129
+ it do
130
+ expect { subclass.send(:with_locals, :error) }
131
+ .not_to change(klass, :locals)
132
+ end
133
+ end
134
+ end
135
+
136
+ describe 'with_attribute_locals' do
137
+ it do
138
+ expect { klass.send(:with_attribute_locals, :field, :model) }
139
+ .to change(klass, :locals)
140
+ .from([])
141
+ .to(%i[field model])
142
+ end
143
+
144
+ it do
145
+ expect { klass.send(:with_attribute_locals, :field, :model) }
146
+ .not_to change(Magicka::Element, :locals)
147
+ end
148
+
149
+ it do
150
+ expect { klass.send(:with_attribute_locals, :field) }
151
+ .to add_method(:field)
152
+ .to(klass)
153
+ end
154
+
155
+ context 'when called on subclass' do
156
+ let(:subclass) { Class.new(klass) }
157
+
158
+ before { klass.send(:with_attribute_locals, :field, :model) }
159
+
160
+ it do
161
+ expect { subclass.send(:with_attribute_locals, :error) }
162
+ .to change(subclass, :locals)
163
+ .from(%i[field model])
164
+ .to(%i[field model error])
165
+ end
166
+
167
+ it do
168
+ expect { subclass.send(:with_attribute_locals, :error) }
169
+ .not_to change(klass, :locals)
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Element do
6
+ subject(:element) { klass.new(renderer: renderer) }
7
+
8
+ let(:klass) do
9
+ Class.new(described_class)
10
+ end
11
+
12
+ let(:renderer) { instance_double('renderer') }
13
+ let(:template) { 'templates/forms/element' }
14
+ let(:folder) { 'templates/forms' }
15
+ let(:locals) { {} }
16
+
17
+ let(:method_builder) { Sinclair.new(klass) }
18
+ let(:expected_template) { template }
19
+
20
+ describe '#render' do
21
+ before do
22
+ allow(renderer)
23
+ .to receive(:render)
24
+ .with(partial: expected_template, locals: locals)
25
+ end
26
+
27
+ context 'when class has a defined template' do
28
+ before do
29
+ klass.template(template)
30
+ end
31
+
32
+ it do
33
+ element.render
34
+
35
+ expect(renderer).to have_received(:render)
36
+ end
37
+
38
+ context 'when initialized with extra params' do
39
+ subject(:element) do
40
+ klass.new(renderer: renderer, name: 'Name')
41
+ end
42
+
43
+ it do
44
+ element.render
45
+
46
+ expect(renderer).to have_received(:render)
47
+ end
48
+ end
49
+
50
+ context 'when class have locals defined' do
51
+ subject(:element) do
52
+ klass.new(renderer: renderer, name: 'Name')
53
+ end
54
+
55
+ let(:locals) { { name: 'Name' } }
56
+
57
+ before do
58
+ klass.send(:with_attribute_locals, :name)
59
+ end
60
+
61
+ it do
62
+ element.render
63
+
64
+ expect(renderer).to have_received(:render)
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'when class has only folder defined' do
70
+ let(:expected_template) { 'templates/forms/my_element' }
71
+
72
+ before do
73
+ klass.template_folder(folder)
74
+
75
+ method_builder.add_class_method(:name) { 'Magicka::MyElement' }
76
+ method_builder.build
77
+ end
78
+
79
+ it do
80
+ element.render
81
+
82
+ expect(renderer).to have_received(:render)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::FormElement do
6
+ let(:renderer) { instance_double('renderer') }
7
+ let(:template) { 'templates/forms/custom_template' }
8
+
9
+ let(:expected_template) { template }
10
+
11
+ let(:model) { :my_model }
12
+ let(:field) { :field }
13
+ let(:label) { 'Label' }
14
+ let(:klass) { Class.new(described_class) }
15
+
16
+ let(:locals) do
17
+ {
18
+ field: field,
19
+ label: label,
20
+ ng_errors: 'my_model.errors.field',
21
+ ng_model: 'my_model.field'
22
+ }
23
+ end
24
+
25
+ describe '.render' do
26
+ let(:arguments) do
27
+ {
28
+ renderer: renderer,
29
+ field: field,
30
+ label: label,
31
+ model: model
32
+ }
33
+ end
34
+
35
+ before do
36
+ allow(renderer)
37
+ .to receive(:render)
38
+ .with(partial: expected_template, locals: locals)
39
+ end
40
+
41
+ context 'when defined template' do
42
+ before do
43
+ klass.template(template)
44
+ end
45
+
46
+ it do
47
+ klass.render(arguments)
48
+
49
+ expect(renderer).to have_received(:render)
50
+ end
51
+
52
+ context 'when called with extra params' do
53
+ it do
54
+ klass.render(name: 'Name', **arguments)
55
+
56
+ expect(renderer).to have_received(:render)
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'when not defining a template' do
62
+ let(:method_builder) { Sinclair.new(klass) }
63
+ let(:expected_template) { 'templates/forms/my_custom_element' }
64
+
65
+ before do
66
+ method_builder.add_class_method(:name) do
67
+ 'Magicka::MyCustomElement'
68
+ end
69
+ method_builder.build
70
+ end
71
+
72
+ it do
73
+ klass.render(arguments)
74
+
75
+ expect(renderer).to have_received(:render)
76
+ end
77
+
78
+ context 'when called with extra params' do
79
+ it do
80
+ klass.render(name: 'Name', **arguments)
81
+
82
+ expect(renderer).to have_received(:render)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Input do
6
+ let(:renderer) { instance_double('renderer') }
7
+ let(:template) { 'templates/forms/input' }
8
+
9
+ let(:model) { :my_model }
10
+ let(:field) { :field }
11
+ let(:label) { 'Label' }
12
+ let(:placeholder) { 'Value' }
13
+
14
+ let(:locals) do
15
+ {
16
+ field: field,
17
+ label: label,
18
+ ng_errors: 'my_model.errors.field',
19
+ ng_model: 'my_model.field',
20
+ placeholder: placeholder
21
+ }
22
+ end
23
+
24
+ describe '.render' do
25
+ let(:arguments) do
26
+ {
27
+ renderer: renderer,
28
+ field: field,
29
+ label: label,
30
+ placeholder: placeholder,
31
+ model: model
32
+ }
33
+ end
34
+
35
+ before do
36
+ allow(renderer)
37
+ .to receive(:render)
38
+ .with(partial: template, locals: locals)
39
+ end
40
+
41
+ it do
42
+ described_class.render(arguments)
43
+
44
+ expect(renderer).to have_received(:render)
45
+ end
46
+
47
+ context 'when called with extra params' do
48
+ it do
49
+ described_class.render(name: 'Name', **arguments)
50
+
51
+ expect(renderer).to have_received(:render)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::MethodBuilder do
6
+ subject(:builder) { described_class.new(klass) }
7
+
8
+ let(:klass) { Class.new }
9
+ let(:instance) { klass.new }
10
+
11
+ describe '#add_template' do
12
+ let(:template) { 'path_to_template' }
13
+
14
+ it do
15
+ expect { builder.add_template(template) }
16
+ .to add_method(:template)
17
+ .to(klass)
18
+ end
19
+
20
+ context 'when method is build as requested' do
21
+ before { builder.add_template(template) }
22
+
23
+ it 'returns the defined template when method is called' do
24
+ expect(instance.template).to eq(template)
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#add_template_folder' do
30
+ let(:folder) { 'path_to_template_folder' }
31
+
32
+ it do
33
+ expect { builder.add_template_folder(folder) }
34
+ .to add_method(:template_folder)
35
+ .to(klass)
36
+ end
37
+
38
+ context 'when method is build as requested' do
39
+ before { builder.add_template_folder(folder) }
40
+
41
+ it 'returns the defined template folder when method is called' do
42
+ expect(instance.template_folder).to eq(folder)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Magicka::Select do
6
+ let(:renderer) { instance_double('renderer') }
7
+ let(:template) { 'templates/forms/select' }
8
+
9
+ let(:model) { :my_model }
10
+ let(:field) { :field }
11
+ let(:label) { 'Label' }
12
+ let(:options) { %i[option_a option_b] }
13
+
14
+ let(:locals) do
15
+ {
16
+ field: field,
17
+ label: label,
18
+ ng_errors: 'my_model.errors.field',
19
+ ng_model: 'my_model.field',
20
+ options: options
21
+ }
22
+ end
23
+
24
+ describe '.render' do
25
+ let(:arguments) do
26
+ {
27
+ renderer: renderer,
28
+ field: field,
29
+ label: label,
30
+ model: model,
31
+ options: options
32
+ }
33
+ end
34
+
35
+ before do
36
+ allow(renderer)
37
+ .to receive(:render)
38
+ .with(partial: template, locals: locals)
39
+ end
40
+
41
+ it do
42
+ described_class.render(arguments)
43
+
44
+ expect(renderer).to have_received(:render)
45
+ end
46
+
47
+ context 'when called with extra params' do
48
+ it do
49
+ described_class.render(name: 'Name', **arguments)
50
+
51
+ expect(renderer).to have_received(:render)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -2,12 +2,10 @@
2
2
 
3
3
  require 'simplecov'
4
4
 
5
- SimpleCov.profiles.define 'gem' do
5
+ SimpleCov.start do
6
6
  add_filter '/spec/'
7
7
  end
8
8
 
9
- SimpleCov.start 'gem'
10
-
11
9
  require 'magicka'
12
10
  require 'pry-nav'
13
11
 
@@ -20,6 +18,7 @@ require File.expand_path('spec/dummy/config/environment')
20
18
  require File.expand_path('spec/dummy/db/schema.rb')
21
19
  require 'rspec/rails'
22
20
  require 'active_support/railtie'
21
+ require 'sinclair/matchers'
23
22
 
24
23
  support_files = File.expand_path('spec/support/**/*.rb')
25
24
  Dir[support_files].sort.each { |file| require file }
@@ -34,4 +33,5 @@ RSpec.configure do |config|
34
33
  config.filter_run_excluding :integration unless ENV['ALL']
35
34
 
36
35
  config.order = 'random'
36
+ config.include Sinclair::Matchers
37
37
  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.0.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-24 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.4.2
19
+ version: 5.2.4.3
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
- version: 5.2.4.2
26
+ version: 5.2.4.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sinclair
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.6
33
+ version: 1.6.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.6
40
+ version: 1.6.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: actionpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 5.2.4.2
47
+ version: 5.2.4.3
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
- version: 5.2.4.2
54
+ version: 5.2.4.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 5.2.4.2
61
+ version: 5.2.4.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 5.2.4.2
68
+ version: 5.2.4.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 5.2.4.2
145
+ version: 5.2.4.3
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 5.2.4.2
152
+ version: 5.2.4.3
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rails-controller-testing
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -397,6 +397,13 @@ files:
397
397
  - config/yardstick.yml
398
398
  - docker-compose.yml
399
399
  - lib/magicka.rb
400
+ - lib/magicka/button.rb
401
+ - lib/magicka/element.rb
402
+ - lib/magicka/element/class_methods.rb
403
+ - lib/magicka/form_element.rb
404
+ - lib/magicka/input.rb
405
+ - lib/magicka/method_builder.rb
406
+ - lib/magicka/select.rb
400
407
  - lib/magicka/version.rb
401
408
  - magicka.gemspec
402
409
  - magicka.jpg
@@ -461,7 +468,13 @@ files:
461
468
  - spec/dummy/storage/.keep
462
469
  - spec/integration/readme/.keep
463
470
  - spec/integration/yard/.keep
464
- - spec/lib/magicka_spec.rb
471
+ - spec/lib/magicka/button_spec.rb
472
+ - spec/lib/magicka/element/class_methods_spec.rb
473
+ - spec/lib/magicka/element_spec.rb
474
+ - spec/lib/magicka/form_element_spec.rb
475
+ - spec/lib/magicka/input_spec.rb
476
+ - spec/lib/magicka/method_builder_spec.rb
477
+ - spec/lib/magicka/select_spec.rb
465
478
  - spec/spec_helper.rb
466
479
  - spec/support/models/.keep
467
480
  - spec/support/shared_examples/.keep
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Magicka do
6
- it 'does something' do
7
- end
8
- end