affairs_of_state 0.7.2 → 0.8.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: 37d765f3c10fc68d7888ecde5f4b71736e70a85ccb77311f110f22772a5bfad3
4
- data.tar.gz: 0b7a6965aad1f602356640b5d2c666bfcc60566e90fc54fd9c11cbd2394d92ea
3
+ metadata.gz: b6e957966743ad1594fb59e99fe593d5caa5cb485e127aa32b6e22a4a3f2ae65
4
+ data.tar.gz: df9d8acf31cbca9d763b15cecd9fe1d3d0ef6425cd6c8022473225d6b67bc9fc
5
5
  SHA512:
6
- metadata.gz: 41dc25892417048d6de1ba7e6927ea335e7ce46819e834943358f5bf03b1397dad3e6aa846ea725a5eec162f5c7bc63e2b6ef8c1812e751683eeec255f868031
7
- data.tar.gz: f28c08bebd42bf3c3a8b0a49308cc6f01161d5ad6840774ad4fb00f391e5d02e2d4730f6090acea7d274ade88b3eaf5e60eb651218da0563f1e4d21ac688a4f3
6
+ metadata.gz: c7c813fce85044e3b2c5b1cd7317445753ba29f27ec81bc77563bccab82ad4296beb031860eaecc1f2b8d261a6a63312a804af7f60d103da7b551a6e542c9d08
7
+ data.tar.gz: 4669e4abd461e51f2af767f021beed0d18c17eeb484cc41284d54b4895c009d3f6328c8fc125803d2c29bbcef5c29fcc1aeeedbe25e3f5b90dc3c8a856e492fb
@@ -10,14 +10,14 @@ Gem::Specification.new do |gem|
10
10
  gem.license = 'MIT'
11
11
 
12
12
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
- gem.files = `git ls-files`.split("\n")
13
+ gem.files = `git ls-files`.split("\n").reject { |f| f.match?(/gemfiles\/|\.github|\.gitignore|Gemfile\.lock|\.ruby_version|\.gitkeep/) }
14
14
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  gem.name = "affairs_of_state"
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = AffairsOfState::VERSION
18
18
 
19
- gem.add_dependency "activerecord", ">= 6.0"
20
- gem.add_dependency "activesupport", ">= 6.0"
19
+ gem.add_dependency "activerecord", ">= 8.0"
20
+ gem.add_dependency "activesupport", ">= 8.0"
21
21
 
22
22
  gem.add_development_dependency "rspec", ">= 3.0"
23
23
  gem.add_development_dependency "sqlite3", ">= 1.4.0"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module AffairsOfState
3
- VERSION = "0.7.2"
3
+ VERSION = "0.8.0"
4
4
  end
@@ -2,13 +2,19 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe AffairsOfState do
5
+ def create_class(&block)
6
+ klass = Class.new(ActiveRecord::Base, &block)
7
+ klass.table_name = "pies"
8
+ klass
9
+ end
10
+
5
11
  describe "with a simple configuration" do
6
- class Pie < ActiveRecord::Base
7
- affairs_of_state :active, :inactive, :cancelled
12
+ subject do
13
+ create_class do
14
+ affairs_of_state :active, :inactive, :cancelled
15
+ end
8
16
  end
9
17
 
10
- subject { Pie }
11
-
12
18
  it "should validate the column is set" do
13
19
  expect(subject.new(status: nil)).to_not be_valid
14
20
  end
@@ -68,14 +74,12 @@ describe AffairsOfState do
68
74
  end
69
75
 
70
76
  describe "with a non-standard column name" do
71
- class Pie2 < ActiveRecord::Base
72
- self.table_name = "pies"
73
-
74
- affairs_of_state :active, :inactive, column: :super_status
77
+ subject do
78
+ create_class do
79
+ affairs_of_state :active, :inactive, column: :super_status
80
+ end
75
81
  end
76
82
 
77
- subject { Pie2 }
78
-
79
83
  it "should validate the column is set" do
80
84
  expect(subject.new(status: nil, super_status: "active")).to be_valid
81
85
  end
@@ -92,58 +96,50 @@ describe AffairsOfState do
92
96
  end
93
97
 
94
98
  describe "without validations" do
95
- class Pie3 < ActiveRecord::Base
96
- self.table_name = "pies"
97
-
98
- affairs_of_state :active, :inactive, allow_blank: true
99
+ subject do
100
+ create_class do
101
+ affairs_of_state :active, :inactive, allow_blank: true
102
+ end
99
103
  end
100
104
 
101
- subject { Pie3 }
102
-
103
105
  it "should validate the column is set" do
104
106
  expect(subject.new(status: nil)).to be_valid
105
107
  end
106
108
  end
107
109
 
108
110
  describe "with an array rather than *args" do
109
- class Pie4 < ActiveRecord::Base
110
- self.table_name = "pies"
111
-
112
- affairs_of_state [:on, :off]
111
+ subject do
112
+ create_class do
113
+ affairs_of_state [:on, :off]
114
+ end
113
115
  end
114
116
 
115
- subject { Pie4 }
116
-
117
117
  it "should work too if that's what floats your boat" do
118
118
  expect(subject.statuses).to eq(["on", "off"])
119
119
  end
120
120
  end
121
121
 
122
122
  describe "without the scopes" do
123
- class Pie5 < ActiveRecord::Base
124
- self.table_name = "pies"
125
-
126
- affairs_of_state :active, :inactive, scopes: false
123
+ subject do
124
+ create_class do
125
+ affairs_of_state :active, :inactive, scopes: false
126
+ end
127
127
  end
128
128
 
129
- subject { Pie5 }
130
-
131
129
  it "should not respond if the scopes are not needed" do
132
130
  expect(subject).to_not respond_to(:active)
133
131
  end
134
132
  end
135
133
 
136
134
  describe "with a conditional proc" do
137
- class Pie6 < ActiveRecord::Base
138
- self.table_name = "pies"
139
-
140
- affairs_of_state :active, :inactive, if: lambda{|p| p.is_going_to_validate }
135
+ subject do
136
+ create_class do
137
+ affairs_of_state :active, :inactive, if: lambda{|p| p.is_going_to_validate }
141
138
 
142
- attr_accessor :is_going_to_validate
139
+ attr_accessor :is_going_to_validate
140
+ end
143
141
  end
144
142
 
145
- subject { Pie6 }
146
-
147
143
  it "should enforce the validation if the :if param is true" do
148
144
  p = subject.new
149
145
  p.is_going_to_validate = true
@@ -160,20 +156,18 @@ describe AffairsOfState do
160
156
  end
161
157
 
162
158
  describe "with a conditional method name" do
163
- class Pie7 < ActiveRecord::Base
164
- self.table_name = "pies"
159
+ subject do
160
+ create_class do
161
+ affairs_of_state :active, :inactive, if: :validation_method?
165
162
 
166
- affairs_of_state :active, :inactive, if: :validation_method?
163
+ attr_accessor :is_going_to_validate
167
164
 
168
- attr_accessor :is_going_to_validate
169
-
170
- def validation_method?
171
- self.is_going_to_validate
165
+ def validation_method?
166
+ self.is_going_to_validate
167
+ end
172
168
  end
173
169
  end
174
170
 
175
- subject { Pie7 }
176
-
177
171
  it "should enforce the validation if the :if param is true" do
178
172
  p = subject.new
179
173
  p.is_going_to_validate = true
@@ -196,15 +190,13 @@ describe AffairsOfState do
196
190
  end
197
191
 
198
192
  describe "multiple invocations" do
199
- class Pie9 < ActiveRecord::Base
200
- self.table_name = "pies"
201
-
202
- affairs_of_state :active, :inactive
203
- affairs_of_state :moderated, :unmoderated, column: :super_status
193
+ subject do
194
+ create_class do
195
+ affairs_of_state :active, :inactive
196
+ affairs_of_state :moderated, :unmoderated, column: :super_status
197
+ end
204
198
  end
205
199
 
206
- subject { Pie9 }
207
-
208
200
  it "declares two status columns" do
209
201
  p = subject.new
210
202
  p.inactive!
@@ -215,9 +207,7 @@ describe AffairsOfState do
215
207
 
216
208
  it "raises if called twice on the same column" do
217
209
  expect {
218
- class Pie10 < ActiveRecord::Base
219
- self.table_name = "pies"
220
-
210
+ create_class do
221
211
  affairs_of_state :active, :inactive
222
212
  affairs_of_state :moderated, :unmoderated
223
213
  end
@@ -226,9 +216,7 @@ describe AffairsOfState do
226
216
 
227
217
  it "raises if called twice with the same status in both" do
228
218
  expect {
229
- class Pie11 < ActiveRecord::Base
230
- self.table_name = "pies"
231
-
219
+ create_class do
232
220
  affairs_of_state :active, :inactive
233
221
  affairs_of_state :dormant, :active, column: :super_status
234
222
  end
@@ -237,9 +225,7 @@ describe AffairsOfState do
237
225
 
238
226
  it "raises if collision between prefixes" do
239
227
  expect {
240
- class Pie12 < ActiveRecord::Base
241
- self.table_name = "pies"
242
-
228
+ create_class do
243
229
  affairs_of_state :admin_active, :admin_inactive
244
230
  affairs_of_state :dormant, :active, column: :super_status, prefix: :admin
245
231
  end
@@ -270,16 +256,14 @@ describe AffairsOfState do
270
256
  end
271
257
 
272
258
  describe "multiple invocations with prefix" do
273
- class Pie13 < ActiveRecord::Base
274
- self.table_name = "pies"
275
-
276
- affairs_of_state :active, :inactive
277
- affairs_of_state :moderated, :unmoderated, column: :super_status
278
- affairs_of_state :positive, :mixed, :negative, column: :sentiment, prefix: :sentiment
259
+ subject do
260
+ create_class do
261
+ affairs_of_state :active, :inactive
262
+ affairs_of_state :moderated, :unmoderated, column: :super_status
263
+ affairs_of_state :positive, :mixed, :negative, column: :sentiment, prefix: :sentiment
264
+ end
279
265
  end
280
266
 
281
- subject { Pie13 }
282
-
283
267
  it "returns the statuses" do
284
268
  expect(subject.statuses(:sentiment)).to eq([ "positive", "mixed", "negative" ])
285
269
  end
@@ -300,4 +284,25 @@ describe AffairsOfState do
300
284
  expect(subject.sentiment_positive).to eq([p])
301
285
  end
302
286
  end
287
+
288
+ describe "with mixed prefix and column" do
289
+ subject do
290
+ create_class do
291
+ affairs_of_state :uploaded, :pending, :blank, column: :avatar_status, prefix: :avatar
292
+ end
293
+ end
294
+
295
+ it "adds the expected methods" do
296
+ p = subject.create! avatar_status: "uploaded"
297
+ expect(p).to be_avatar_uploaded
298
+ expect(p).to_not be_avatar_pending
299
+ expect(p).to_not be_avatar_blank
300
+ p.avatar_pending!
301
+ expect(p).to be_avatar_pending
302
+ expect(p).to_not be_avatar_uploaded
303
+ expect(p).to_not be_avatar_blank
304
+ p.avatar_blank!
305
+ expect(p).to be_avatar_blank
306
+ end
307
+ end
303
308
  end
data/spec/spec_helper.rb CHANGED
@@ -22,4 +22,5 @@ ActiveRecord::Base.connection.create_table(:pies) do |t|
22
22
  t.string :status
23
23
  t.string :super_status
24
24
  t.string :sentiment
25
+ t.string :avatar_status
25
26
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: affairs_of_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McPhillips
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-09-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -16,28 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '6.0'
18
+ version: '8.0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '6.0'
25
+ version: '8.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: activesupport
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '6.0'
32
+ version: '8.0'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '6.0'
39
+ version: '8.0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -88,19 +87,12 @@ executables: []
88
87
  extensions: []
89
88
  extra_rdoc_files: []
90
89
  files:
91
- - ".github/workflows/ci.yml"
92
- - ".gitignore"
93
90
  - ".rspec"
94
- - ".ruby_version"
95
91
  - Gemfile
96
92
  - LICENSE
97
93
  - README.md
98
94
  - Rakefile
99
95
  - affairs_of_state.gemspec
100
- - gemfiles/activerecord-6.0.gemfile
101
- - gemfiles/activerecord-6.1.gemfile
102
- - gemfiles/activerecord-7.0.gemfile
103
- - gemfiles/activerecord-latest.gemfile
104
96
  - lib/affairs_of_state.rb
105
97
  - lib/affairs_of_state/active_record_extension.rb
106
98
  - lib/affairs_of_state/config.rb
@@ -113,7 +105,6 @@ homepage: http://github.com/kmcphillips/affairs_of_state
113
105
  licenses:
114
106
  - MIT
115
107
  metadata: {}
116
- post_install_message:
117
108
  rdoc_options: []
118
109
  require_paths:
119
110
  - lib
@@ -128,10 +119,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
119
  - !ruby/object:Gem::Version
129
120
  version: '0'
130
121
  requirements: []
131
- rubygems_version: 3.2.22
132
- signing_key:
122
+ rubygems_version: 3.7.2
133
123
  specification_version: 4
134
124
  summary: You have an Active Record model. It nees to have multiple states, but not
135
125
  complex rules. This gem gives you validation, easy check and change methods, and
136
126
  a single configuration line.
137
- test_files: []
127
+ test_files:
128
+ - spec/affairs_of_state_spec.rb
129
+ - spec/config_spec.rb
130
+ - spec/db/.gitkeep
131
+ - spec/spec_helper.rb
@@ -1,26 +0,0 @@
1
- name: CI
2
-
3
- on: [ push, pull_request ]
4
-
5
- jobs:
6
- test:
7
- strategy:
8
- fail-fast: false
9
- matrix:
10
- gemfile:
11
- - "activerecord-6.0.gemfile"
12
- - "activerecord-6.1.gemfile"
13
- - "activerecord-7.0.gemfile"
14
- - "activerecord-latest.gemfile"
15
- runs-on: ubuntu-latest
16
- env:
17
- BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}
18
- steps:
19
- - uses: actions/checkout@v2
20
- - uses: ruby/setup-ruby@v1
21
- with:
22
- ruby-version: 3.0.2
23
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
24
- - name: Run tests
25
- run: |
26
- bundle exec rspec --format doc
data/.gitignore DELETED
@@ -1,19 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- spec/db/test.sqlite3
19
-
data/.ruby_version DELETED
@@ -1 +0,0 @@
1
- 3.0.2
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'activerecord', '~> 6.0'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'activerecord', '~> 6.1'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'activerecord', '~> 7.0'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'activerecord'