eac_active_scaffold 0.3.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5cc04435477ea32bbf31c2189530aba0922da6cbf39cddeb288b34202a0a059
4
- data.tar.gz: ddc743b6a429d04f1971a20b4d0ee93b335ed33c8b82c6236a8da5d7f4a4c7b8
3
+ metadata.gz: 9d69265751bd71af4268328c69b1b30d69cffa89a179c90e6041c78ccf152511
4
+ data.tar.gz: 2c4bed407eb53bf70d8ed1598fd66a9c5b26e6cf0c997ac44406c7b20bbc46ce
5
5
  SHA512:
6
- metadata.gz: fa40fddc77968d294eca75f46a75b573a34ffa65ce2a48c23f8de8c29cec60b85c2e1cd75610e41fa0696d62c229e9ac40317dcb915a09b94d0143f781979832
7
- data.tar.gz: b9e62f051d4103e5f65981997883a6a925356389b0e07487936bd10301d8a2fabe6233277941bd45a956cbc502013ff2fe846397b1a2f51c7a627308ca931f57
6
+ metadata.gz: 0a0b3e704a4e8f067df54f5c7da30e6b16c009b2529fc43f90d57fa75a4e2b6d85722ef262b7007b03638b839acac8793f257f727af65451a142fa64ebb66fc0
7
+ data.tar.gz: 42f925360f83aa6840825c8c9837acda5180985688080c85d3a3d69afe24d336a9619f8a697c0492c12c7e3a78670a391b3c0892157e6f6557ab0c0d864f2a8f
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacActiveScaffold
6
+ module Rspec
7
+ class ControllerDirector
8
+ class AttributeSet
9
+ enable_method_class
10
+ common_constructor :director, :example, :name, :value
11
+
12
+ def result
13
+ text_fill
14
+ rescue ::Capybara::ElementNotFound
15
+ select_option
16
+ end
17
+
18
+ private
19
+
20
+ # @return [Capybara::Node::Element]
21
+ def field
22
+ example.find_field(label)
23
+ end
24
+
25
+ def label
26
+ director.attribute_label(name)
27
+ end
28
+
29
+ def select_option
30
+ example.within field do
31
+ example.find("option[value='#{value}']").select_option
32
+ end
33
+ end
34
+
35
+ def text_fill
36
+ field.fill_in with: value
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacActiveScaffold
6
+ module Rspec
7
+ class ControllerDirector
8
+ enable_listable
9
+ lists.add_symbol :option, :controller_class, :index_path, :model_class, :valid_data,
10
+ :valid_create_data, :valid_update_data
11
+ common_constructor :example, :options do
12
+ self.options = self.class.lists.option.hash_keys_validate!(options)
13
+ end
14
+
15
+ # @return [String]
16
+ def attribute_label(attr)
17
+ model_class.human_attribute_name(attr)
18
+ end
19
+
20
+ # @param example [RSpec::Core::ExampleGroup]
21
+ # @param attrs [Hash]
22
+ # @return [void]
23
+ def attributes_set(example, attrs)
24
+ attrs.each { |attr, value| attribute_set(example, attr, value) }
25
+ end
26
+
27
+ # @return [Class]
28
+ def controller_class
29
+ options[:controller_class] || example.described_class
30
+ end
31
+
32
+ # @return [String]
33
+ def index_path
34
+ options.fetch(OPTION_INDEX_PATH)
35
+ end
36
+
37
+ # @return [Class]
38
+ def model_class
39
+ options[OPTION_MODEL_CLASS] || controller_class.active_scaffold_config.model
40
+ end
41
+
42
+ # @return [String]
43
+ def page_title
44
+ model_class.model_name.human(count: 2)
45
+ end
46
+
47
+ # @return [Hash]
48
+ def valid_create_data
49
+ options[OPTION_VALID_CREATE_DATA] || valid_data
50
+ end
51
+
52
+ # @return [Hash]
53
+ def valid_data
54
+ options.fetch(OPTION_VALID_DATA)
55
+ end
56
+
57
+ # @return [Hash]
58
+ def valid_update_data
59
+ options[OPTION_VALID_UPDATE_DATA] || valid_data
60
+ end
61
+
62
+ require_sub __FILE__, require_mode: :kernel
63
+ end
64
+ end
65
+ end
@@ -1,24 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ::RSpec.shared_context 'active_scaffold_controller' do |options|
4
- let(:index_path) { options.fetch(:index_path) }
5
- let(:model) { options.fetch(:model) }
3
+ require 'eac_active_scaffold/rspec/controller_director'
4
+
5
+ ::RSpec.shared_context 'active_scaffold_controller' do |options| # rubocop:disable Metrics/BlockLength
6
+ director = ::EacActiveScaffold::Rspec::ControllerDirector.new(self, options)
6
7
 
7
8
  before do
8
- visit index_path
9
+ visit director.index_path
9
10
  end
10
11
 
11
12
  it 'show index page' do
12
- expect(page).to have_content model.model_name.human(count: 2)
13
+ expect(page).to have_content director.page_title
13
14
  end
14
15
 
15
- it 'create new record' do
16
- expect do
16
+ context 'when record is created' do # rubocop:disable Metrics/BlockLength
17
+ let(:before_create_count) { director.model_class.count }
18
+ let(:created_record) { director.model_class.first }
19
+ let(:record_href) { %r{/#{::Regexp.quote(created_record.id.to_s)}} }
20
+ let(:edit_link_args) { [::I18n.t('active_scaffold.edit'), href: record_href] }
21
+ let(:remove_link_args) { [::I18n.t('active_scaffold.remove'), href: record_href] }
22
+ let(:show_link_args) { [::I18n.t('active_scaffold.show'), href: record_href] }
23
+
24
+ before do
25
+ before_create_count
17
26
  click_on ::I18n.t('active_scaffold.create_new')
18
- options.fetch(:valid).each do |key, value|
19
- fill_in model.human_attribute_name(key), with: value
20
- end
27
+ director.attributes_set(self, director.valid_create_data)
21
28
  click_on ::I18n.t('active_scaffold.create')
22
- end.to change { model.count }.by(1)
29
+ end
30
+
31
+ it 'increments record count' do
32
+ expect(director.model_class.count).to eq(before_create_count + 1)
33
+ end
34
+
35
+ it 'have a edit link for record' do
36
+ expect(page).to have_link(*edit_link_args)
37
+ end
38
+
39
+ it 'have a remove link for record' do
40
+ expect(page).to have_link(*remove_link_args)
41
+ end
42
+
43
+ it 'have a show link for record' do
44
+ expect(page).to have_link(*show_link_args)
45
+ end
46
+
47
+ context 'when record is updated' do
48
+ let(:before_update_count) { director.model_class.count }
49
+
50
+ before do
51
+ before_update_count
52
+ click_link(*edit_link_args)
53
+ director.attributes_set(self, director.valid_update_data)
54
+ click_on ::I18n.t('active_scaffold.update')
55
+ end
56
+
57
+ it 'unchanges record count' do
58
+ expect(director.model_class.count).to eq(before_update_count)
59
+ end
60
+ end
61
+
62
+ context 'when record is destroyed' do
63
+ let(:before_destroy_count) { director.model_class.count }
64
+
65
+ before do
66
+ before_destroy_count
67
+ click_link(*remove_link_args)
68
+ end
69
+
70
+ it 'decrements record count' do
71
+ expect(director.model_class.count).to eq(before_destroy_count - 1)
72
+ end
73
+ end
23
74
  end
24
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacActiveScaffold
4
- VERSION = '0.3.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-30 00:00:00.000000000 Z
11
+ date: 2023-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_scaffold
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '3.6'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 3.6.17
22
+ version: 3.6.19
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '3.6'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 3.6.17
32
+ version: 3.6.19
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eac_ruby_utils
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +83,8 @@ files:
83
83
  - lib/eac_active_scaffold/patches.rb
84
84
  - lib/eac_active_scaffold/patches/action_dispatch.rb
85
85
  - lib/eac_active_scaffold/rspec.rb
86
+ - lib/eac_active_scaffold/rspec/controller_director.rb
87
+ - lib/eac_active_scaffold/rspec/controller_director/attribute_set.rb
86
88
  - lib/eac_active_scaffold/rspec/setup.rb
87
89
  - lib/eac_active_scaffold/rspec/shared_contexts/active_scaffold_controller.rb
88
90
  - lib/eac_active_scaffold/version.rb