eac_active_scaffold 0.3.0 → 0.4.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: e5cc04435477ea32bbf31c2189530aba0922da6cbf39cddeb288b34202a0a059
4
- data.tar.gz: ddc743b6a429d04f1971a20b4d0ee93b335ed33c8b82c6236a8da5d7f4a4c7b8
3
+ metadata.gz: 97c012d3f0f8e7e4471a86abdffc2909783da3973fb4289870b672480b618c28
4
+ data.tar.gz: 3801ffdf4e9b3c608d077b151ce25fad53aa787e67a948314a42bc8f998b5dbd
5
5
  SHA512:
6
- metadata.gz: fa40fddc77968d294eca75f46a75b573a34ffa65ce2a48c23f8de8c29cec60b85c2e1cd75610e41fa0696d62c229e9ac40317dcb915a09b94d0143f781979832
7
- data.tar.gz: b9e62f051d4103e5f65981997883a6a925356389b0e07487936bd10301d8a2fabe6233277941bd45a956cbc502013ff2fe846397b1a2f51c7a627308ca931f57
6
+ metadata.gz: df68a482be337f5db59d0bfd34826364600d0a8439a9c9ea5b4e646cf64d857f74b16d6cf4111028a0327c16bd3a9cce1715ab0764aeb87aa3737fab47f26629
7
+ data.tar.gz: b2d33e2698cb46fc587587569e1bb831f0f0320a7d2e65a0ab8a5864e7ebd373bc682e503c187bf8d0fdb4ac86dabd4a1743b9b7ac0fa5bd769a0af45d355ba2
@@ -0,0 +1,56 @@
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
+ # @return [Class]
21
+ def controller_class
22
+ options[:controller_class] || example.described_class
23
+ end
24
+
25
+ # @return [String]
26
+ def index_path
27
+ options.fetch(OPTION_INDEX_PATH)
28
+ end
29
+
30
+ # @return [Class]
31
+ def model_class
32
+ options[OPTION_MODEL_CLASS] || controller_class.active_scaffold_config.model
33
+ end
34
+
35
+ # @return [String]
36
+ def page_title
37
+ model_class.model_name.human(count: 2)
38
+ end
39
+
40
+ # @return [Hash]
41
+ def valid_create_data
42
+ options[OPTION_VALID_CREATE_DATA] || valid_data
43
+ end
44
+
45
+ # @return [Hash]
46
+ def valid_data
47
+ options.fetch(OPTION_VALID_DATA)
48
+ end
49
+
50
+ # @return [Hash]
51
+ def valid_update_data
52
+ options[OPTION_VALID_UPDATE_DATA] || valid_data
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,24 +1,79 @@
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
27
+ director.valid_create_data.each do |key, value|
28
+ fill_in director.attribute_label(key), with: value
20
29
  end
21
30
  click_on ::I18n.t('active_scaffold.create')
22
- end.to change { model.count }.by(1)
31
+ end
32
+
33
+ it 'increments record count' do
34
+ expect(director.model_class.count).to eq(before_create_count + 1)
35
+ end
36
+
37
+ it 'have a edit link for record' do
38
+ expect(page).to have_link(*edit_link_args)
39
+ end
40
+
41
+ it 'have a remove link for record' do
42
+ expect(page).to have_link(*remove_link_args)
43
+ end
44
+
45
+ it 'have a show link for record' do
46
+ expect(page).to have_link(*show_link_args)
47
+ end
48
+
49
+ context 'when record is updated' do
50
+ let(:before_update_count) { director.model_class.count }
51
+
52
+ before do
53
+ before_update_count
54
+ click_link(*edit_link_args)
55
+ director.valid_update_data.each do |key, value|
56
+ fill_in director.attribute_label(key), with: value
57
+ end
58
+ click_on ::I18n.t('active_scaffold.update')
59
+ end
60
+
61
+ it 'unchanges record count' do
62
+ expect(director.model_class.count).to eq(before_update_count)
63
+ end
64
+ end
65
+
66
+ context 'when record is destroyed' do
67
+ let(:before_destroy_count) { director.model_class.count }
68
+
69
+ before do
70
+ before_destroy_count
71
+ click_link(*remove_link_args)
72
+ end
73
+
74
+ it 'decrements record count' do
75
+ expect(director.model_class.count).to eq(before_destroy_count - 1)
76
+ end
77
+ end
23
78
  end
24
79
  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.4.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.4.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-10 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,7 @@ 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
86
87
  - lib/eac_active_scaffold/rspec/setup.rb
87
88
  - lib/eac_active_scaffold/rspec/shared_contexts/active_scaffold_controller.rb
88
89
  - lib/eac_active_scaffold/version.rb