magicka 0.2.1 → 0.3.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
2
  SHA256:
3
- metadata.gz: acb4390fb75581e4146370ded48a252086bd7be06f625dfdbfaecabd402b8a10
4
- data.tar.gz: 38713bd185d41bcc4ae44e1a78fbb3d197bec36d93bf6eb3627b5cafda022478
3
+ metadata.gz: 36b0fd245209516aea68b26b93305a7bb3bd2c25a37bab33a1642f61c3ddaf8a
4
+ data.tar.gz: 69c0fb47a36f70010329381bdded763d45269a0b51b9984d83af78d34b56dcf7
5
5
  SHA512:
6
- metadata.gz: b25dc0ff77238004cce929acadcb22122c5f3f97b43992914563ee9e7da1c5bba81e12bef61b837a19215b46cc0a01dfdf1d59e4c6f0a4dddc249390c4341654
7
- data.tar.gz: 6eb4eab985fe5648ada7917786725a210d23092e1b70004fa434ca15375046f0e390307b96cbe958c96d2c22ec5c7516d5a593f3f07a7733ef60a0cc0e7be81d
6
+ metadata.gz: e59e3a6feef27c1d2dca549497db8704a15ef8f3fe103ae4ebaa8a7c6b04ac7dfd918c5a097c0395043b00981368e2bd7614e94eacc6d47b69ddb6f6892a6a3d
7
+ data.tar.gz: dfa188ef2f10ffbff7e3e2f8fa43495e28bfffd6d84f573ba695bc9d4c2e25a6b454a5f39bfa1e195c74636e33378d194bc43d32594a021c78f0443996afe412
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.2,1](https://www.rubydoc.info/gems/magicka/0.2.1)
14
+ [https://www.rubydoc.info/gems/magicka/0.3.0](https://www.rubydoc.info/gems/magicka/0.3.0)
15
15
 
16
16
  Installation
17
17
  ---------------
@@ -12,7 +12,8 @@ require 'sinclair'
12
12
  module Magicka
13
13
  autoload :VERSION, 'magicka/version'
14
14
  autoload :Element, 'magicka/element'
15
+ autoload :FormElement, 'magicka/form_element'
15
16
  autoload :Input, 'magicka/input'
16
- autoload :InputElement, 'magicka/input_element'
17
17
  autoload :MethodBuilder, 'magicka/method_builder'
18
+ autoload :Select, 'magicka/select'
18
19
  end
@@ -4,7 +4,7 @@ module Magicka
4
4
  # @api public
5
5
  #
6
6
  # Basic class for elements for forms
7
- class InputElement < Element
7
+ class FormElement < Element
8
8
  with_attribute_locals :field, :label
9
9
  with_attributes :model
10
10
  with_locals :ng_errors, :ng_model
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Magicka
4
4
  # Input element representing an HTML +<input/>+
5
- class Input < InputElement
5
+ class Input < FormElement
6
6
  with_attribute_locals :placeholder
7
7
  end
8
8
  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
3
  module Magicka
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -67,12 +67,12 @@ describe Magicka::Element do
67
67
  end
68
68
 
69
69
  context 'when class has only folder defined' do
70
- let(:expected_template) { 'templates/forms/input' }
70
+ let(:expected_template) { 'templates/forms/my_element' }
71
71
 
72
72
  before do
73
73
  klass.template_folder(folder)
74
74
 
75
- method_builder.add_class_method(:name) { 'Magicka::Input' }
75
+ method_builder.add_class_method(:name) { 'Magicka::MyElement' }
76
76
  method_builder.build
77
77
  end
78
78
 
@@ -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
@@ -2,34 +2,33 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Magicka::InputElement do
5
+ describe Magicka::Select do
6
6
  let(:renderer) { instance_double('renderer') }
7
- let(:template) { 'templates/forms/input' }
7
+ let(:template) { 'templates/forms/select' }
8
8
 
9
9
  let(:model) { :my_model }
10
10
  let(:field) { :field }
11
11
  let(:label) { 'Label' }
12
+ let(:options) { %i[option_a option_b] }
12
13
 
13
14
  let(:locals) do
14
15
  {
15
16
  field: field,
16
17
  label: label,
17
18
  ng_errors: 'my_model.errors.field',
18
- ng_model: 'my_model.field'
19
+ ng_model: 'my_model.field',
20
+ options: options
19
21
  }
20
22
  end
21
23
 
22
- before do
23
- described_class.template(template)
24
- end
25
-
26
24
  describe '.render' do
27
25
  let(:arguments) do
28
26
  {
29
27
  renderer: renderer,
30
28
  field: field,
31
29
  label: label,
32
- model: model
30
+ model: model,
31
+ options: options
33
32
  }
34
33
  end
35
34
 
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.2.1
4
+ version: 0.3.0
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-02 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
@@ -399,9 +399,10 @@ files:
399
399
  - lib/magicka.rb
400
400
  - lib/magicka/element.rb
401
401
  - lib/magicka/element/class_methods.rb
402
+ - lib/magicka/form_element.rb
402
403
  - lib/magicka/input.rb
403
- - lib/magicka/input_element.rb
404
404
  - lib/magicka/method_builder.rb
405
+ - lib/magicka/select.rb
405
406
  - lib/magicka/version.rb
406
407
  - magicka.gemspec
407
408
  - magicka.jpg
@@ -468,9 +469,10 @@ files:
468
469
  - spec/integration/yard/.keep
469
470
  - spec/lib/magicka/element/class_methods_spec.rb
470
471
  - spec/lib/magicka/element_spec.rb
471
- - spec/lib/magicka/input_element_spec.rb
472
+ - spec/lib/magicka/form_element_spec.rb
472
473
  - spec/lib/magicka/input_spec.rb
473
474
  - spec/lib/magicka/method_builder_spec.rb
475
+ - spec/lib/magicka/select_spec.rb
474
476
  - spec/spec_helper.rb
475
477
  - spec/support/models/.keep
476
478
  - spec/support/shared_examples/.keep