magicka 0.6.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/.rubocop.yml +8 -1
- data/Dockerfile +3 -2
- data/README.md +5 -1
- data/config/check_specs.yml +0 -2
- data/config/yardstick.yml +8 -2
- data/lib/magicka/aggregator/method_builder.rb +35 -28
- data/lib/magicka/aggregator.rb +16 -8
- data/lib/magicka/display.rb +1 -1
- data/lib/magicka/element/class_methods.rb +2 -0
- data/lib/magicka/element.rb +4 -2
- data/lib/magicka/helper/aggregator_options.rb +64 -0
- data/lib/magicka/helper/class_methods.rb +10 -2
- data/lib/magicka/helper/method_builder.rb +10 -6
- data/lib/magicka/helper.rb +12 -6
- data/lib/magicka/version.rb +1 -1
- data/magicka.gemspec +9 -7
- data/spec/dummy/app/controllers/application_controller.rb +1 -0
- data/spec/dummy/app/controllers/documents_controller.rb +9 -0
- data/spec/dummy/app/models/document.rb +5 -0
- data/spec/dummy/app/models/magicka/data_entry.rb +7 -0
- data/spec/dummy/app/models/magicka/data_table.rb +6 -0
- data/spec/dummy/app/views/documents/show.html.erb +6 -0
- data/spec/dummy/app/views/templates/display/_data_entry.html.erb +2 -0
- data/spec/dummy/config/environments/development.rb +1 -0
- data/spec/dummy/config/initializers/magicka.rb +7 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/dummy/db/schema.rb +5 -0
- data/spec/integration/yard/magicka/helper_spec.rb +33 -0
- data/spec/lib/magicka/aggregator/class_methods_spec.rb +352 -0
- data/spec/lib/magicka/aggregator/method_builder_spec.rb +29 -0
- data/spec/lib/magicka/aggregator_spec.rb +0 -221
- data/spec/lib/magicka/button_spec.rb +1 -1
- data/spec/lib/magicka/display_spec.rb +3 -3
- data/spec/lib/magicka/form_element_spec.rb +2 -2
- data/spec/lib/magicka/form_spec.rb +3 -3
- data/spec/lib/magicka/helper/aggregator_options_spec.rb +99 -0
- data/spec/lib/magicka/helper/class_methods_spec.rb +101 -0
- data/spec/lib/magicka/helper_spec.rb +2 -18
- data/spec/lib/magicka/input_spec.rb +1 -1
- data/spec/lib/magicka/select_spec.rb +1 -1
- data/spec/lib/magicka/text_spec.rb +1 -1
- data/spec/support/factories/document.rb +7 -0
- data/spec/support/factory_bot.rb +7 -0
- data/spec/support/models/custom_aggregator.rb +12 -0
- data/spec/support/models/my_element.rb +6 -0
- metadata +69 -25
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::Helper::AggregatorOptions do
|
6
|
+
subject(:options) { described_class.new(options_hash) }
|
7
|
+
|
8
|
+
let(:options_hash) do
|
9
|
+
{
|
10
|
+
aggregator: aggregator,
|
11
|
+
type: type,
|
12
|
+
config_block: config_block
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:aggregator_class) { Class.new(Magicka::Aggregator) }
|
17
|
+
let(:aggregator) { aggregator_class }
|
18
|
+
let(:type) { :my_aggregator }
|
19
|
+
let(:config_block) do
|
20
|
+
proc { with_element(Magicka::Input) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#configured_aggregator' do
|
24
|
+
let(:renderer) { instance_double(ActionView::OutputBuffer) }
|
25
|
+
let(:model) { Object.new }
|
26
|
+
let(:element_class) { Magicka::Input }
|
27
|
+
|
28
|
+
before do
|
29
|
+
allow(element_class).to receive(:render).with(
|
30
|
+
renderer: renderer,
|
31
|
+
field: :name,
|
32
|
+
model: model,
|
33
|
+
template: nil
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when aggregator is a class' do
|
38
|
+
context 'when config block is given' do
|
39
|
+
it 'returns the given aggregator class' do
|
40
|
+
expect(options.configured_aggregator)
|
41
|
+
.to be(aggregator)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'configure the aggregator' do
|
45
|
+
options.configured_aggregator.new(renderer, model)
|
46
|
+
.input(:name)
|
47
|
+
|
48
|
+
expect(element_class).to have_received(:render)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when config block is not given' do
|
53
|
+
let(:config_block) { nil }
|
54
|
+
|
55
|
+
it 'returns the given aggregator class' do
|
56
|
+
expect(options.configured_aggregator)
|
57
|
+
.to be(aggregator)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when aggregator is a String' do
|
63
|
+
let(:aggregator) { "Magicka::#{aggregator_name}" }
|
64
|
+
let(:aggregator_name) { :CustomAggregator }
|
65
|
+
|
66
|
+
before { Magicka.const_set(aggregator_name, aggregator_class) }
|
67
|
+
|
68
|
+
context 'when config block is given' do
|
69
|
+
let(:aggregator_name) { :CustomAggregator1 }
|
70
|
+
|
71
|
+
it 'returns the given aggregator class' do
|
72
|
+
expect(options.configured_aggregator)
|
73
|
+
.to be(aggregator_class)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when config block is given and is called' do
|
78
|
+
let(:aggregator_name) { :CustomAggregator2 }
|
79
|
+
|
80
|
+
it 'configure the aggregator' do
|
81
|
+
options.configured_aggregator.new(renderer, model)
|
82
|
+
.input(:name)
|
83
|
+
|
84
|
+
expect(element_class).to have_received(:render)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when config block is not given' do
|
89
|
+
let(:aggregator_name) { :CustomAggregator3 }
|
90
|
+
let(:config_block) { nil }
|
91
|
+
|
92
|
+
it 'returns the given aggregator class' do
|
93
|
+
expect(options.configured_aggregator)
|
94
|
+
.to be(aggregator_class)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Magicka::Helper::ClassMethods do
|
6
|
+
subject(:object) { klass.new }
|
7
|
+
|
8
|
+
let(:model) { Object.new }
|
9
|
+
|
10
|
+
let(:helper_class) { Magicka::Helper }
|
11
|
+
let(:klass) do
|
12
|
+
Class.new do
|
13
|
+
include Magicka::Helper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#with' do
|
18
|
+
let(:aggregator_class) do
|
19
|
+
Class.new(Magicka::Aggregator) do
|
20
|
+
def self.name
|
21
|
+
'Magicka::MyClass'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when passing a class' do
|
27
|
+
it do
|
28
|
+
expect { helper_class.with(aggregator_class) }
|
29
|
+
.to add_method('magicka_my_class')
|
30
|
+
.to(object)
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when the method is called' do
|
34
|
+
before { helper_class.with(aggregator_class) }
|
35
|
+
|
36
|
+
it do
|
37
|
+
object.magicka_my_class(model) do |aggregator|
|
38
|
+
expect(aggregator).to be_a(aggregator_class)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when an element is added in the block' do
|
44
|
+
before do
|
45
|
+
helper_class.with(aggregator_class) do
|
46
|
+
with_element(Magicka::Input, :my_input)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it do
|
51
|
+
object.magicka_my_class(model) do |aggregator|
|
52
|
+
expect(aggregator).to respond_to(:my_input)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when passing a string as agregator' do
|
59
|
+
let(:aggregator_name) { :Test1Aggregator }
|
60
|
+
let(:aggregator_class_name) { "Magicka::#{aggregator_name}" }
|
61
|
+
|
62
|
+
it do
|
63
|
+
expect { helper_class.with(aggregator_class_name, :test1_aggregator) }
|
64
|
+
.to add_method('magicka_test1_aggregator')
|
65
|
+
.to(object)
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when the method is called' do
|
69
|
+
before do
|
70
|
+
helper_class.with(aggregator_class_name, :test1_aggregator)
|
71
|
+
|
72
|
+
Magicka.const_set(aggregator_name, aggregator_class)
|
73
|
+
end
|
74
|
+
|
75
|
+
it do
|
76
|
+
object.magicka_test1_aggregator(model) do |aggregator|
|
77
|
+
expect(aggregator).to be_a(aggregator_class)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when an element is added in the block' do
|
83
|
+
let(:aggregator_name) { :Test2Aggregator }
|
84
|
+
|
85
|
+
before do
|
86
|
+
helper_class.with(aggregator_class_name, :test2_aggregator) do
|
87
|
+
with_element(Magicka::Input, :my_input)
|
88
|
+
end
|
89
|
+
|
90
|
+
Magicka.const_set(aggregator_name, aggregator_class)
|
91
|
+
end
|
92
|
+
|
93
|
+
it do
|
94
|
+
object.magicka_test2_aggregator(model) do |aggregator|
|
95
|
+
expect(aggregator).to respond_to(:my_input)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -5,30 +5,14 @@ require 'spec_helper'
|
|
5
5
|
describe Magicka::Helper do
|
6
6
|
subject(:object) { klass.new }
|
7
7
|
|
8
|
+
let(:model) { Object.new }
|
9
|
+
|
8
10
|
let(:klass) do
|
9
11
|
Class.new do
|
10
12
|
include Magicka::Helper
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
let(:model) { 'model' }
|
15
|
-
|
16
|
-
describe '.with' do
|
17
|
-
let(:aggregator_class) do
|
18
|
-
Class.new(Magicka::Aggregator) do
|
19
|
-
def self.name
|
20
|
-
'Magicka::MyClass'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it do
|
26
|
-
expect { described_class.with(aggregator_class) }
|
27
|
-
.to add_method('magicka_my_class')
|
28
|
-
.to(object)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
16
|
describe '#magicka_display' do
|
33
17
|
it do
|
34
18
|
object.magicka_display(model) do |display|
|
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.0.x
|
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:
|
26
|
+
version: 7.0.x
|
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:
|
33
|
+
version: 2.0.1
|
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:
|
40
|
+
version: 2.0.1
|
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:
|
47
|
+
version: 7.0.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:
|
54
|
+
version: 7.0.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:
|
61
|
+
version: 7.0.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:
|
68
|
+
version: 7.0.4.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.3.25
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.3.25
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: factory_bot
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: rails
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 7.0.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:
|
152
|
+
version: 7.0.4.3
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rails-controller-testing
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -332,6 +332,20 @@ dependencies:
|
|
332
332
|
- - '='
|
333
333
|
- !ruby/object:Gem::Version
|
334
334
|
version: 0.17.1
|
335
|
+
- !ruby/object:Gem::Dependency
|
336
|
+
name: sprockets-rails
|
337
|
+
requirement: !ruby/object:Gem::Requirement
|
338
|
+
requirements:
|
339
|
+
- - '='
|
340
|
+
- !ruby/object:Gem::Version
|
341
|
+
version: 3.4.2
|
342
|
+
type: :development
|
343
|
+
prerelease: false
|
344
|
+
version_requirements: !ruby/object:Gem::Requirement
|
345
|
+
requirements:
|
346
|
+
- - '='
|
347
|
+
- !ruby/object:Gem::Version
|
348
|
+
version: 3.4.2
|
335
349
|
- !ruby/object:Gem::Dependency
|
336
350
|
name: sqlite3
|
337
351
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,6 +360,20 @@ dependencies:
|
|
346
360
|
- - '='
|
347
361
|
- !ruby/object:Gem::Version
|
348
362
|
version: 1.4.2
|
363
|
+
- !ruby/object:Gem::Dependency
|
364
|
+
name: tzinfo-data
|
365
|
+
requirement: !ruby/object:Gem::Requirement
|
366
|
+
requirements:
|
367
|
+
- - "~>"
|
368
|
+
- !ruby/object:Gem::Version
|
369
|
+
version: 1.2022.1
|
370
|
+
type: :development
|
371
|
+
prerelease: false
|
372
|
+
version_requirements: !ruby/object:Gem::Requirement
|
373
|
+
requirements:
|
374
|
+
- - "~>"
|
375
|
+
- !ruby/object:Gem::Version
|
376
|
+
version: 1.2022.1
|
349
377
|
- !ruby/object:Gem::Dependency
|
350
378
|
name: yard
|
351
379
|
requirement: !ruby/object:Gem::Requirement
|
@@ -408,6 +436,7 @@ files:
|
|
408
436
|
- lib/magicka/form.rb
|
409
437
|
- lib/magicka/form_element.rb
|
410
438
|
- lib/magicka/helper.rb
|
439
|
+
- lib/magicka/helper/aggregator_options.rb
|
411
440
|
- lib/magicka/helper/class_methods.rb
|
412
441
|
- lib/magicka/helper/method_builder.rb
|
413
442
|
- lib/magicka/input.rb
|
@@ -428,14 +457,20 @@ files:
|
|
428
457
|
- spec/dummy/app/channels/application_cable/connection.rb
|
429
458
|
- spec/dummy/app/controllers/application_controller.rb
|
430
459
|
- spec/dummy/app/controllers/concerns/.keep
|
460
|
+
- spec/dummy/app/controllers/documents_controller.rb
|
431
461
|
- spec/dummy/app/helpers/application_helper.rb
|
432
462
|
- spec/dummy/app/jobs/application_job.rb
|
433
463
|
- spec/dummy/app/mailers/application_mailer.rb
|
434
464
|
- spec/dummy/app/models/application_record.rb
|
435
465
|
- spec/dummy/app/models/concerns/.keep
|
466
|
+
- spec/dummy/app/models/document.rb
|
467
|
+
- spec/dummy/app/models/magicka/data_entry.rb
|
468
|
+
- spec/dummy/app/models/magicka/data_table.rb
|
469
|
+
- spec/dummy/app/views/documents/show.html.erb
|
436
470
|
- spec/dummy/app/views/layouts/application.html.erb
|
437
471
|
- spec/dummy/app/views/layouts/mailer.html.erb
|
438
472
|
- spec/dummy/app/views/layouts/mailer.text.erb
|
473
|
+
- spec/dummy/app/views/templates/display/_data_entry.html.erb
|
439
474
|
- spec/dummy/bin/bundle
|
440
475
|
- spec/dummy/bin/rails
|
441
476
|
- spec/dummy/bin/rake
|
@@ -458,6 +493,7 @@ files:
|
|
458
493
|
- spec/dummy/config/initializers/cookies_serializer.rb
|
459
494
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
460
495
|
- spec/dummy/config/initializers/inflections.rb
|
496
|
+
- spec/dummy/config/initializers/magicka.rb
|
461
497
|
- spec/dummy/config/initializers/mime_types.rb
|
462
498
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
463
499
|
- spec/dummy/config/locales/en.yml
|
@@ -477,6 +513,9 @@ files:
|
|
477
513
|
- spec/dummy/storage/.keep
|
478
514
|
- spec/integration/readme/.keep
|
479
515
|
- spec/integration/yard/.keep
|
516
|
+
- spec/integration/yard/magicka/helper_spec.rb
|
517
|
+
- spec/lib/magicka/aggregator/class_methods_spec.rb
|
518
|
+
- spec/lib/magicka/aggregator/method_builder_spec.rb
|
480
519
|
- spec/lib/magicka/aggregator_spec.rb
|
481
520
|
- spec/lib/magicka/button_spec.rb
|
482
521
|
- spec/lib/magicka/display_spec.rb
|
@@ -485,12 +524,18 @@ files:
|
|
485
524
|
- spec/lib/magicka/element_spec.rb
|
486
525
|
- spec/lib/magicka/form_element_spec.rb
|
487
526
|
- spec/lib/magicka/form_spec.rb
|
527
|
+
- spec/lib/magicka/helper/aggregator_options_spec.rb
|
528
|
+
- spec/lib/magicka/helper/class_methods_spec.rb
|
488
529
|
- spec/lib/magicka/helper_spec.rb
|
489
530
|
- spec/lib/magicka/input_spec.rb
|
490
531
|
- spec/lib/magicka/select_spec.rb
|
491
532
|
- spec/lib/magicka/text_spec.rb
|
492
533
|
- spec/spec_helper.rb
|
534
|
+
- spec/support/factories/document.rb
|
535
|
+
- spec/support/factory_bot.rb
|
493
536
|
- spec/support/models/.keep
|
537
|
+
- spec/support/models/custom_aggregator.rb
|
538
|
+
- spec/support/models/my_element.rb
|
494
539
|
- spec/support/shared_examples/.keep
|
495
540
|
homepage: https://github.com/darthjee/magicka
|
496
541
|
licenses: []
|
@@ -503,15 +548,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
503
548
|
requirements:
|
504
549
|
- - ">="
|
505
550
|
- !ruby/object:Gem::Version
|
506
|
-
version: 2.
|
551
|
+
version: 2.7.0
|
507
552
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
508
553
|
requirements:
|
509
554
|
- - ">="
|
510
555
|
- !ruby/object:Gem::Version
|
511
556
|
version: '0'
|
512
557
|
requirements: []
|
513
|
-
|
514
|
-
rubygems_version: 2.7.6
|
558
|
+
rubygems_version: 3.1.2
|
515
559
|
signing_key:
|
516
560
|
specification_version: 4
|
517
561
|
summary: Gem for easy form templating
|