eac_active_scaffold 0.2.3 → 0.4.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: ede215cb2cf301d5dbe839a93be45a13eba4988d5746aed8da6efe9f57d98910
4
- data.tar.gz: 6c87c45db09b325108a4c4120f18cf96fa1d5756dcee972c719d556999fb798a
3
+ metadata.gz: 97c012d3f0f8e7e4471a86abdffc2909783da3973fb4289870b672480b618c28
4
+ data.tar.gz: 3801ffdf4e9b3c608d077b151ce25fad53aa787e67a948314a42bc8f998b5dbd
5
5
  SHA512:
6
- metadata.gz: 97faab77dd80415461f9e0a69410f3138c9afc629e28be846f1f48620c6cc80056555eb7da9830b697c24f94294feb287aead631906b3295c0e9ef5ca8b8c810
7
- data.tar.gz: 4224bc31ffe0789297a8199338d48828c33559cf68a459c2c9cb0b7c24331ad43df7acb79b4bd359eb5d3214f10878707443b192342063470ab9d15de595fb2c
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
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacActiveScaffold
6
+ module Rspec
7
+ module Setup
8
+ def self.extended(obj)
9
+ %w[controller_example].each do |m|
10
+ obj.send("setup_#{m}")
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def setup_controller_example
17
+ require 'eac_active_scaffold/rspec/shared_contexts/active_scaffold_controller'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
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)
7
+
8
+ before do
9
+ visit director.index_path
10
+ end
11
+
12
+ it 'show index page' do
13
+ expect(page).to have_content director.page_title
14
+ end
15
+
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
26
+ click_on ::I18n.t('active_scaffold.create_new')
27
+ director.valid_create_data.each do |key, value|
28
+ fill_in director.attribute_label(key), with: value
29
+ end
30
+ click_on ::I18n.t('active_scaffold.create')
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
78
+ end
79
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacActiveScaffold
6
+ module Rspec
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacActiveScaffold
4
- VERSION = '0.2.3'
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.2.3
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: 2022-07-05 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
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.6.11
19
+ version: '3.6'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 3.6.11.1
22
+ version: 3.6.19
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 3.6.11
29
+ version: '3.6'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 3.6.11.1
32
+ version: 3.6.19
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eac_ruby_utils
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.95'
39
+ version: '0.117'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 0.95.1
42
+ version: 0.117.1
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0.95'
49
+ version: '0.117'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.95.1
52
+ version: 0.117.1
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: eac_rails_gem_support
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +82,10 @@ files:
82
82
  - lib/eac_active_scaffold/engine.rb
83
83
  - lib/eac_active_scaffold/patches.rb
84
84
  - lib/eac_active_scaffold/patches/action_dispatch.rb
85
+ - lib/eac_active_scaffold/rspec.rb
86
+ - lib/eac_active_scaffold/rspec/controller_director.rb
87
+ - lib/eac_active_scaffold/rspec/setup.rb
88
+ - lib/eac_active_scaffold/rspec/shared_contexts/active_scaffold_controller.rb
85
89
  - lib/eac_active_scaffold/version.rb
86
90
  homepage:
87
91
  licenses: []