act_with_flags 0.0.6 → 0.2.4
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 +4 -4
- data/.github/workflows/rake.yml +24 -0
- data/.rubocop.yml +4 -74
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/.watchr +6 -14
- data/Appraisals +11 -0
- data/Gemfile +1 -4
- data/MIT-LICENSE +20 -0
- data/README.md +0 -1
- data/Rakefile +3 -15
- data/act_with_flags.gemspec +7 -2
- data/gemfiles/rails_6.0.gemfile +14 -0
- data/gemfiles/rails_6.1.gemfile +14 -0
- data/lib/act_with_flags/admin.rb +7 -5
- data/lib/act_with_flags/define.rb +12 -1
- data/lib/act_with_flags/utils.rb +2 -3
- data/lib/act_with_flags/version.rb +7 -6
- data/test/any_all_none_test.rb +4 -2
- data/test/clear_test.rb +1 -1
- data/test/inheritance_any_test.rb +56 -0
- data/test/inheritance_test.rb +73 -0
- data/test/internal/app/assets/config/manifest.js +1 -0
- data/test/internal/app/controllers/application_controller.rb +3 -0
- data/test/internal/app/controllers/orders_controller.rb +16 -0
- data/test/internal/app/models/application_record.rb +3 -0
- data/test/internal/app/models/order.rb +9 -0
- data/test/internal/app/views/layouts/application.html.erb +12 -0
- data/test/internal/config/database.yml +3 -0
- data/test/internal/config/routes.rb +4 -0
- data/test/internal/config/secrets.yml +8 -0
- data/test/internal/db/schema.rb +13 -0
- data/test/internal_benchmark_test.rb +5 -8
- data/test/internal_check_add_test.rb +4 -0
- data/test/internal_null_test.rb +3 -3
- data/test/internal_one_test.rb +2 -0
- data/test/legacy_test.rb +1 -1
- data/test/one_test.rb +1 -1
- data/test/origin_test.rb +2 -0
- data/test/remove_from_test.rb +1 -1
- data/test/reset_test.rb +1 -1
- data/test/test_helper.rb +8 -25
- metadata +96 -13
- data/.travis.yml +0 -19
- data/LICENSE +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c723baaa15bf9f4e86987bb20e3c85984cb465d7758ab05866a41baaa6ed5a1
|
4
|
+
data.tar.gz: 29ac2c9336dedd278f2e3ee2a71710a4cc34117c07bc28869b989e5cf454cccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bd31e1bf3a0f0a6721fa8ed916ae799e20022b46bfc78521f13ccd40d359737812bb4ae35a02ef601d0e654551f758eea795cc2defe8e0079301bda5e2644bb
|
7
|
+
data.tar.gz: 51a34e9a84543e5d36a709f82332b5a188414ee0425723fb1a25a483574d2ab0bc1b33a60d629d4e055808acdfb982fdc8e0983806e6d4a2ad2c9669479b3106
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Rake
|
2
|
+
|
3
|
+
#on: [push, pull_request]
|
4
|
+
on: [push]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
# os: [ubuntu-latest, macos-latest]
|
12
|
+
os: [ubuntu-latest]
|
13
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
14
|
+
# ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head]
|
15
|
+
ruby: [2.7]
|
16
|
+
runs-on: ${{ matrix.os }}
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
24
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,79 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# rubocop --auto-gen-config
|
4
|
-
# rubocop
|
5
|
-
# rubocop:disable all
|
6
|
-
|
7
|
-
#inherit_from: .rubocop_todo.yml
|
1
|
+
inherit_from:
|
2
|
+
- ~/configs/.rubocop.yml
|
8
3
|
|
9
4
|
AllCops:
|
5
|
+
NewCops: enable
|
10
6
|
Include:
|
11
|
-
- 'app/**/*.rb'
|
12
|
-
- 'bin/**/*.rb'
|
13
|
-
- 'lib/**/*.rb'
|
14
|
-
|
15
|
-
- 'config/**/*.rb'
|
16
|
-
- 'db/**/*.rb'
|
17
7
|
- 'lib/**/*.rb'
|
18
|
-
- 'test/**/*.rb' # 581 offenses
|
19
|
-
- '**/*.gemfile'
|
20
|
-
- '**/*.gemspec'
|
21
|
-
- '**/*.rake'
|
22
|
-
- '**/*.ru'
|
23
|
-
- '**/Gemfile'
|
24
|
-
# - '**/Rakefile'
|
25
|
-
|
26
|
-
#AllCops:
|
27
|
-
# Exclude:
|
28
|
-
# - 'db/**/*'
|
29
|
-
# - 'config/**/*'
|
30
|
-
# - 'script/**/*'
|
31
|
-
# - 'bin/{rails,rake}'
|
32
|
-
# - 'spec/**/*'
|
33
|
-
# - !ruby/regexp /old_and_unused\.rb$/
|
34
|
-
|
35
|
-
Bundler/OrderedGems:
|
36
|
-
Exclude:
|
37
|
-
- 'Gemfile'
|
38
|
-
|
39
|
-
Layout/AccessModifierIndentation:
|
40
|
-
Enabled: false
|
41
|
-
Layout/AlignArray:
|
42
|
-
Enabled: false
|
43
|
-
Layout/CommentIndentation:
|
44
|
-
Enabled: false
|
45
|
-
Layout/EmptyLinesAroundAccessModifier:
|
46
|
-
Enabled: false
|
47
|
-
Layout/EmptyLinesAroundBlockBody:
|
48
|
-
Enabled: false
|
49
|
-
Layout/EmptyLinesAroundClassBody:
|
50
|
-
Enabled: false
|
51
|
-
Layout/ExtraSpacing:
|
52
|
-
Enabled: false
|
53
|
-
Layout/IndentArray:
|
54
|
-
Enabled: false
|
55
|
-
Layout/IndentationWidth:
|
56
|
-
Enabled: false
|
57
|
-
Layout/LeadingCommentSpace:
|
58
|
-
Enabled: false
|
59
|
-
Layout/Tab:
|
60
|
-
Enabled: false
|
61
|
-
|
62
|
-
Lint/UnusedBlockArgument:
|
63
|
-
Enabled: false
|
64
|
-
|
65
|
-
Style/BlockDelimiters:
|
66
|
-
Enabled: false
|
67
|
-
Style/Documentation:
|
68
|
-
Enabled: false
|
69
|
-
Style/FormatString:
|
70
|
-
Enabled: false
|
71
|
-
Style/FrozenStringLiteralComment:
|
72
|
-
Enabled: false
|
73
|
-
Style/WhenThen:
|
74
8
|
Exclude:
|
75
|
-
- '
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
9
|
+
- 'test/**/*'
|
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rails-
|
1
|
+
rails-6.1
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.2
|
data/.watchr
CHANGED
@@ -16,38 +16,30 @@ end
|
|
16
16
|
|
17
17
|
def run_it(type, file)
|
18
18
|
case type
|
19
|
-
|
20
|
-
when '
|
21
|
-
# when 'test'; run %Q{rails test #{file}}
|
22
|
-
# when 'spec'; run %Q{spring rspec -X #{file}}
|
19
|
+
when 'test'; run %(bundle exec ruby -I test #{file})
|
20
|
+
# when 'spec'; run %(rspec -X #{file})
|
23
21
|
else; puts "#{H} unknown type: #{type}, file: #{file}"
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
25
|
def run_all_tests
|
28
26
|
puts "\n#{HH} Running all tests #{HH}\n"
|
29
|
-
|
30
|
-
# %w{test}.each { |dir| run "spring rake #{dir} RAILS_ENV=test" if File.exists?(dir) }
|
31
|
-
%w{test}.each { |dir| run "rake #{dir} RAILS_ENV=test" if File.exists?(dir) }
|
27
|
+
%w[test spec].each { |dir| run "bundle exec rake #{dir}" if File.exist?(dir) }
|
32
28
|
end
|
33
29
|
|
34
30
|
def run_matching_files(base)
|
35
31
|
base = base.split('_').first
|
36
|
-
%w
|
32
|
+
%w[test spec].each { |type|
|
37
33
|
files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
|
38
34
|
run_it type, files.join(' ') unless files.empty?
|
39
35
|
}
|
40
36
|
end
|
41
37
|
|
42
|
-
%w
|
38
|
+
%w[test spec].each { |type|
|
43
39
|
watch("#{type}/#{type}_helper\.rb") { run_all_tests }
|
40
|
+
watch('lib/.*\.rb') { run_all_tests }
|
44
41
|
watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
|
45
42
|
}
|
46
|
-
%w{rb erb haml slim}.each { |type|
|
47
|
-
watch("app/.*/.*\.#{type}") { |m|
|
48
|
-
run_matching_files("#{m[0].split('/').at(2).split('.').first}")
|
49
|
-
}
|
50
|
-
}
|
51
43
|
|
52
44
|
# Ctrl-\ or ctrl-4
|
53
45
|
Signal.trap('QUIT') { run_all_tests }
|
data/Appraisals
ADDED
data/Gemfile
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
#ruby '2.6.0'
|
3
2
|
gemspec
|
4
3
|
|
5
4
|
gem 'rails'
|
6
5
|
|
7
6
|
group :test do
|
8
7
|
gem 'observr'
|
8
|
+
gem 'rubocop', require: false
|
9
9
|
gem 'simplecov', require: false
|
10
|
-
gem 'minitest'
|
11
|
-
gem 'sqlite3', '!= 1.4.0'
|
12
10
|
gem 'benchmark-ips'
|
13
|
-
# gem 'sqlite3'
|
14
11
|
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019-2020 Dittmar Krall - www.matique.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# ActWithFlags
|
2
2
|
[](http://badge.fury.io/rb/act_with_flags)
|
3
|
-
[](https://travis-ci.org/matique/act_with_flags)
|
4
3
|
|
5
4
|
Required by key.matique.
|
6
5
|
|
data/Rakefile
CHANGED
@@ -1,23 +1,11 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
|
3
1
|
require 'rake/testtask'
|
4
2
|
|
5
|
-
desc '
|
6
|
-
Rake::TestTask.new
|
3
|
+
desc 'Run the tests.'
|
4
|
+
Rake::TestTask.new do |t|
|
7
5
|
t.libs << 'lib'
|
8
6
|
t.libs << 'test'
|
9
7
|
t.pattern = 'test/**/*_test.rb'
|
10
8
|
t.verbose = false
|
11
9
|
end
|
12
10
|
|
13
|
-
task :
|
14
|
-
|
15
|
-
|
16
|
-
=begin
|
17
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
18
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
19
|
-
|
20
|
-
require_relative 'config/application'
|
21
|
-
|
22
|
-
Rails.application.load_tasks
|
23
|
-
=end
|
11
|
+
task default: :test
|
data/act_with_flags.gemspec
CHANGED
@@ -18,6 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.add_development_dependency 'bundler'
|
22
|
-
s.add_development_dependency 'rake'
|
21
|
+
s.add_development_dependency 'bundler'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'appraisal'
|
24
|
+
s.add_development_dependency 'combustion'
|
25
|
+
|
26
|
+
s.add_development_dependency 'minitest'
|
27
|
+
s.add_development_dependency 'sqlite3'
|
23
28
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6.0.0"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "observr"
|
9
|
+
gem "rubocop", require: false
|
10
|
+
gem "simplecov", require: false
|
11
|
+
gem "benchmark-ips"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6.0"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "observr"
|
9
|
+
gem "rubocop", require: false
|
10
|
+
gem "simplecov", require: false
|
11
|
+
gem "benchmark-ips"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
data/lib/act_with_flags/admin.rb
CHANGED
@@ -39,14 +39,16 @@ class ActWithFlags::Admin
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def position(name)
|
42
|
-
@map[name]
|
43
|
-
|
42
|
+
pos = @map[name]
|
43
|
+
return pos if pos
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
parent = self.model.superclass.act_with_flags
|
46
|
+
return parent.position(name) if parent
|
47
|
+
|
48
|
+
raise "unknown flag '#{model}##{name}'"
|
47
49
|
end
|
48
50
|
|
49
|
-
def
|
51
|
+
def mask(*names)
|
50
52
|
names.inject(0) { |msk, name| msk | ( 1 << position(name) ) }
|
51
53
|
end
|
52
54
|
|
@@ -4,12 +4,22 @@
|
|
4
4
|
class ActWithFlags::Admin
|
5
5
|
|
6
6
|
def add_accessors(origin, accessor, mask)
|
7
|
+
#p ["act_with_flags#add_accessors:", model, origin, accessor, mask]
|
8
|
+
unless model.method_defined?(:act_with_flags)
|
9
|
+
model.class_eval %(
|
10
|
+
def act_with_flags
|
11
|
+
#{model}.act_with_flags
|
12
|
+
end
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
7
16
|
model.class_eval %(
|
8
17
|
def #{accessor}
|
9
18
|
#{accessor}?
|
10
19
|
end
|
11
20
|
|
12
21
|
def #{accessor}?
|
22
|
+
raise "Uninitialized '#{model}.#{origin}'" if #{origin}.nil?
|
13
23
|
if #{origin}.is_a?(String)
|
14
24
|
flags = self.#{origin}.to_i
|
15
25
|
!( flags & #{mask} ).zero?
|
@@ -19,11 +29,12 @@ class ActWithFlags::Admin
|
|
19
29
|
end
|
20
30
|
|
21
31
|
def #{accessor}=(value)
|
32
|
+
raise "Uninitialized '#{model}.#{origin}'" if #{origin}.nil?
|
22
33
|
is_a_string = #{origin}.is_a?(String)
|
23
34
|
flags = is_a_string ? self.#{origin}.to_i : self.#{origin}
|
24
35
|
flags ||= 0
|
25
36
|
|
26
|
-
result = self.
|
37
|
+
result = self.act_with_flags.to_boolean(value)
|
27
38
|
if result
|
28
39
|
flags |= #{mask}
|
29
40
|
else
|
data/lib/act_with_flags/utils.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# xfrozen_string_literal: true
|
1
|
+
# rubocop: disable all
|
3
2
|
|
4
3
|
class ActWithFlags::Admin
|
5
4
|
|
@@ -46,7 +45,7 @@ class ActWithFlags::Admin
|
|
46
45
|
names.each { |name|
|
47
46
|
remove_accessor name
|
48
47
|
}
|
49
|
-
|
48
|
+
reset_model model
|
50
49
|
end
|
51
50
|
|
52
51
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# rubocop: disable all
|
2
3
|
|
3
4
|
module ActWithFlags
|
4
|
-
VERSION = '0.
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
5
|
+
VERSION = '0.2.4' # 2021-06-21
|
6
|
+
# VERSION = '0.2.3' # 2020-07-14
|
7
|
+
# VERSION = '0.2.2' # 2020-04-27
|
8
|
+
# VERSION = '0.2.1' # 2020-03-01
|
9
|
+
# VERSION = '0.2.0' # 2019-10-04
|
10
|
+
# VERSION = '0.1.0' # 2019-04-07
|
10
11
|
end
|
data/test/any_all_none_test.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe 'any? all? and none?' do
|
4
|
-
let(:order) { Order.
|
6
|
+
let(:order) { Order.create }
|
5
7
|
|
6
8
|
def setup
|
7
9
|
reset_order
|
@@ -30,7 +32,7 @@ describe 'any? all? and none?' do
|
|
30
32
|
end
|
31
33
|
|
32
34
|
it 'checks none? #2' do
|
33
|
-
order.a = order.b =
|
35
|
+
order.a = order.b = true
|
34
36
|
refute order.flags_none?(:a, :b)
|
35
37
|
order.a = false
|
36
38
|
refute order.flags_none?(:a, :b)
|
data/test/clear_test.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class A < Order
|
6
|
+
add_to_flags y: 2
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'inheritance' do
|
10
|
+
let(:a) { A.create }
|
11
|
+
|
12
|
+
def setup
|
13
|
+
reset_order
|
14
|
+
Order.add_to_flags x: 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'consistency' do
|
18
|
+
assert a.respond_to?(:x)
|
19
|
+
assert a.respond_to?(:y)
|
20
|
+
assert_equal false, a.x
|
21
|
+
assert_equal false, a.y
|
22
|
+
a.y = true
|
23
|
+
assert_equal true, a.y
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'checks any?' do
|
27
|
+
a.x = true
|
28
|
+
assert a.flags_any?(:x, :y)
|
29
|
+
a.x = false
|
30
|
+
refute a.flags_any?(:x, :y)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'checks any? #2' do
|
34
|
+
a.y = true
|
35
|
+
assert a.flags_any?(:x, :y)
|
36
|
+
a.y = false
|
37
|
+
refute a.flags_any?(:x, :y)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'checks all?' do
|
41
|
+
a.x = a.y = true
|
42
|
+
assert a.flags_all?(:x, :y)
|
43
|
+
a.x = false
|
44
|
+
refute a.flags_all?(:x, :y)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'checks none? #2' do
|
48
|
+
a.x = a.y = true
|
49
|
+
refute a.flags_none?(:x, :y)
|
50
|
+
a.x = false
|
51
|
+
refute a.flags_none?(:x, :y)
|
52
|
+
a.y = false
|
53
|
+
assert a.flags_none?(:x, :y)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class A < Order
|
6
|
+
end
|
7
|
+
|
8
|
+
class B < Order
|
9
|
+
add_to_flags y: 2
|
10
|
+
end
|
11
|
+
|
12
|
+
class C < Order
|
13
|
+
before_create { |row| row.flags2 = 0 }
|
14
|
+
|
15
|
+
attr_accessor :flags2
|
16
|
+
add_to_flags z: 3, origin: :flags2
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'inheritance' do
|
20
|
+
let(:admina) { A.act_with_flags }
|
21
|
+
let(:adminb) { B.act_with_flags }
|
22
|
+
|
23
|
+
let(:a) { A.create }
|
24
|
+
let(:b) { B.create }
|
25
|
+
let(:c) { C.create }
|
26
|
+
|
27
|
+
def setup
|
28
|
+
reset_order
|
29
|
+
Order.add_to_flags x: 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'inheritance #1' do
|
33
|
+
assert a.respond_to?(:flags)
|
34
|
+
assert a.respond_to?(:x)
|
35
|
+
assert_equal 0, a.flags
|
36
|
+
assert_equal false, a.x
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'inheritance #2' do
|
40
|
+
a.x = false
|
41
|
+
assert_equal false, a.x
|
42
|
+
a.x = true
|
43
|
+
assert_equal true, a.x
|
44
|
+
assert_equal 0x02, a.flags
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'inheritance #3' do
|
48
|
+
assert b.respond_to?(:flags)
|
49
|
+
assert b.respond_to?(:x)
|
50
|
+
assert b.respond_to?(:y)
|
51
|
+
assert_equal 0, b.flags
|
52
|
+
assert_equal false, b.x
|
53
|
+
assert_equal false, b.y
|
54
|
+
b.x = true
|
55
|
+
assert_equal true, b.x
|
56
|
+
b.y = true
|
57
|
+
assert_equal true, b.y
|
58
|
+
assert_equal 0x06, b.flags
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'inheritance #4' do
|
62
|
+
assert c.respond_to?(:x)
|
63
|
+
assert c.respond_to?(:z)
|
64
|
+
assert_equal false, c.z
|
65
|
+
c.x = true
|
66
|
+
assert_equal true, c.x
|
67
|
+
c.z = true
|
68
|
+
assert_equal true, c.z
|
69
|
+
assert_equal 0x02, c.flags
|
70
|
+
assert_equal 0x08, c.flags2
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_tree ../images
|
@@ -0,0 +1,8 @@
|
|
1
|
+
development:
|
2
|
+
secret_key_base: e0759094af00bb172148ef71ce3bfd3cb8ad688628bee51dd596b3c2e84aaf37b94136e5fe9d35e8685e4fcc1b145a3568d0675fdf88fa77751e405d454a80d5
|
3
|
+
|
4
|
+
test:
|
5
|
+
secret_key_base: ad8df0f94e834515e076f0259050f9dc722286a1d305cf4e650242c63cfe6f1a451c4c135e833c90b854720ebd38d741cdb50b9541ab6c505d45559cb5af62b0
|
6
|
+
|
7
|
+
production:
|
8
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ActiveRecord::Schema.define(version: 201910) do
|
2
|
+
|
3
|
+
create_table "orders", force: true do |t|
|
4
|
+
t.string "name"
|
5
|
+
t.string "qty"
|
6
|
+
t.integer "flags"
|
7
|
+
t.text "bigflags"
|
8
|
+
t.integer "category"
|
9
|
+
t.datetime "created_at", null: false
|
10
|
+
t.datetime "updated_at", null: false
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -8,7 +8,7 @@ require 'benchmark/ips'
|
|
8
8
|
# ENV['MORE'] = 'true'
|
9
9
|
|
10
10
|
describe 'Internal timings' do
|
11
|
-
let(:order) { Order.
|
11
|
+
let(:order) { Order.create }
|
12
12
|
|
13
13
|
def setup
|
14
14
|
reset_order
|
@@ -18,9 +18,6 @@ describe 'Internal timings' do
|
|
18
18
|
it 'times ips' do
|
19
19
|
return unless ENV['MORE']
|
20
20
|
|
21
|
-
Order.add_to_flags :blocked, reset: :hard
|
22
|
-
order = Order.new
|
23
|
-
|
24
21
|
Benchmark.ips do |x|
|
25
22
|
x.report('assign true : ') { order.blocked = true }
|
26
23
|
x.report('assign false: ') { order.blocked = false }
|
@@ -42,12 +39,12 @@ class BenchFoo < Minitest::Benchmark
|
|
42
39
|
n = 1_000_000
|
43
40
|
n = 100_000
|
44
41
|
n = 10_000
|
45
|
-
Order.add_to_flags :
|
46
|
-
order = Order.
|
42
|
+
Order.add_to_flags :blocked2
|
43
|
+
order = Order.create
|
47
44
|
assert_performance_constant do |input|
|
48
45
|
n.times do
|
49
|
-
order.
|
50
|
-
order.
|
46
|
+
order.blocked2 = true
|
47
|
+
order.blocked2 = !order.blocked2
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
data/test/internal_null_test.rb
CHANGED
@@ -16,9 +16,9 @@ describe 'Internal Null' do
|
|
16
16
|
it 'tests to_boolean' do
|
17
17
|
assert admin.to_boolean(true)
|
18
18
|
refute admin.to_boolean(false)
|
19
|
-
assert_raises {
|
20
|
-
assert_raises {
|
21
|
-
assert_raises {
|
19
|
+
assert_raises { admin.to_boolean(nil) }
|
20
|
+
assert_raises { admin.to_boolean(2) }
|
21
|
+
assert_raises { admin.to_boolean('unknown') }
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'tests a simple administration: names' do
|
data/test/internal_one_test.rb
CHANGED
data/test/legacy_test.rb
CHANGED
data/test/one_test.rb
CHANGED
data/test/origin_test.rb
CHANGED
data/test/remove_from_test.rb
CHANGED
data/test/reset_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,35 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
if ENV['MORE']
|
1
|
+
if ENV['COVERAGE']
|
4
2
|
require 'simplecov'
|
5
3
|
SimpleCov.start do
|
6
|
-
add_filter 'test'
|
4
|
+
add_filter '/test/'
|
7
5
|
end
|
8
6
|
end
|
9
7
|
|
10
|
-
require
|
8
|
+
require "combustion"
|
9
|
+
Combustion.path = "test/internal"
|
10
|
+
Combustion.initialize! :active_record
|
11
|
+
|
12
|
+
require 'rails/test_help'
|
11
13
|
require 'minitest/autorun'
|
12
14
|
require 'minitest/benchmark'
|
13
|
-
require '
|
14
|
-
require_relative '../lib/act_with_flags.rb'
|
15
|
-
|
16
|
-
ENV['RAILS_ENV'] ||= 'test'
|
17
|
-
|
18
|
-
ActiveRecord::Base.establish_connection(
|
19
|
-
adapter: 'sqlite3',
|
20
|
-
database: 'db/flags.sqlite3'
|
21
|
-
)
|
22
|
-
|
23
|
-
ActiveRecord::Schema.define do
|
24
|
-
create_table 'orders', force: true do |t|
|
25
|
-
t.integer :flags
|
26
|
-
t.string :bigflags
|
27
|
-
t.integer :category
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Order < ActiveRecord::Base
|
32
|
-
end
|
15
|
+
#require 'capybara/rails'
|
33
16
|
|
34
17
|
def reset_order
|
35
18
|
Order.act_with_flags.reset if Order.act_with_flags
|
metadata
CHANGED
@@ -1,43 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act_with_flags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
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: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
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: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: appraisal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: combustion
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
41
97
|
description: Handles flags in a Rails model instance
|
42
98
|
email:
|
43
99
|
- dittmar.krall@matique.de
|
@@ -45,18 +101,21 @@ executables: []
|
|
45
101
|
extensions: []
|
46
102
|
extra_rdoc_files: []
|
47
103
|
files:
|
104
|
+
- ".github/workflows/rake.yml"
|
48
105
|
- ".gitignore"
|
49
106
|
- ".rubocop.yml"
|
50
107
|
- ".ruby-gemset"
|
51
108
|
- ".ruby-version"
|
52
|
-
- ".travis.yml"
|
53
109
|
- ".watchr"
|
110
|
+
- Appraisals
|
54
111
|
- Gemfile
|
55
112
|
- Gemfile.lock
|
56
|
-
- LICENSE
|
113
|
+
- MIT-LICENSE
|
57
114
|
- README.md
|
58
115
|
- Rakefile
|
59
116
|
- act_with_flags.gemspec
|
117
|
+
- gemfiles/rails_6.0.gemfile
|
118
|
+
- gemfiles/rails_6.1.gemfile
|
60
119
|
- lib/act_with_flags.rb
|
61
120
|
- lib/act_with_flags/admin.rb
|
62
121
|
- lib/act_with_flags/define.rb
|
@@ -65,6 +124,18 @@ files:
|
|
65
124
|
- lib/act_with_flags/version.rb
|
66
125
|
- test/any_all_none_test.rb
|
67
126
|
- test/clear_test.rb
|
127
|
+
- test/inheritance_any_test.rb
|
128
|
+
- test/inheritance_test.rb
|
129
|
+
- test/internal/app/assets/config/manifest.js
|
130
|
+
- test/internal/app/controllers/application_controller.rb
|
131
|
+
- test/internal/app/controllers/orders_controller.rb
|
132
|
+
- test/internal/app/models/application_record.rb
|
133
|
+
- test/internal/app/models/order.rb
|
134
|
+
- test/internal/app/views/layouts/application.html.erb
|
135
|
+
- test/internal/config/database.yml
|
136
|
+
- test/internal/config/routes.rb
|
137
|
+
- test/internal/config/secrets.yml
|
138
|
+
- test/internal/db/schema.rb
|
68
139
|
- test/internal_benchmark_test.rb
|
69
140
|
- test/internal_check_add_test.rb
|
70
141
|
- test/internal_null_test.rb
|
@@ -97,13 +168,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
168
|
- !ruby/object:Gem::Version
|
98
169
|
version: '0'
|
99
170
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
171
|
+
rubygems_version: 3.2.6
|
101
172
|
signing_key:
|
102
173
|
specification_version: 4
|
103
174
|
summary: act_with_flags gem
|
104
175
|
test_files:
|
105
176
|
- test/any_all_none_test.rb
|
106
177
|
- test/clear_test.rb
|
178
|
+
- test/inheritance_any_test.rb
|
179
|
+
- test/inheritance_test.rb
|
180
|
+
- test/internal/app/assets/config/manifest.js
|
181
|
+
- test/internal/app/controllers/application_controller.rb
|
182
|
+
- test/internal/app/controllers/orders_controller.rb
|
183
|
+
- test/internal/app/models/application_record.rb
|
184
|
+
- test/internal/app/models/order.rb
|
185
|
+
- test/internal/app/views/layouts/application.html.erb
|
186
|
+
- test/internal/config/database.yml
|
187
|
+
- test/internal/config/routes.rb
|
188
|
+
- test/internal/config/secrets.yml
|
189
|
+
- test/internal/db/schema.rb
|
107
190
|
- test/internal_benchmark_test.rb
|
108
191
|
- test/internal_check_add_test.rb
|
109
192
|
- test/internal_null_test.rb
|
data/.travis.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
|
4
|
-
bundler_args: --without production
|
5
|
-
#before_install:
|
6
|
-
#- gem update bundler --no-document
|
7
|
-
#- gem update bundler --no-rdoc --no-ri
|
8
|
-
script: "bundle exec rake test"
|
9
|
-
|
10
|
-
rvm:
|
11
|
-
- 2.6.1
|
12
|
-
|
13
|
-
gemfile:
|
14
|
-
# - gemfiles/rails_5.2.gemfile
|
15
|
-
|
16
|
-
matrix:
|
17
|
-
|
18
|
-
notifications:
|
19
|
-
email: false
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2019 Dittmar Krall (matique UG)
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|