reform-rails 0.2.5 → 0.3.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: 9d136641745a9b830812afa8cb959e3dfd016166bd08100411481ca3215f3a87
4
- data.tar.gz: d3dcb1ddb5c7d77305bd42382068e8b9fb1f5f6556682529ad742001126394cc
3
+ metadata.gz: 43ce92d480a18dfc398266771235ed677f949aaefef85fca362c787d49b3443b
4
+ data.tar.gz: f6d7d3f34e15f3ee674aacdba842cc0f42d43850f71dbc29d24704903342427a
5
5
  SHA512:
6
- metadata.gz: 98612de254f296d0000e8e942d82c7f249d5b557c97d42fdbaebec433aee338427e00df42be8f3ab106c147465f4ee9afdeac4be593b270bdb6d86e840e04c28
7
- data.tar.gz: 53e08abfcfe1a97bc91191e05159cfcb51f0f2d0d831bf3ed7ef4b7cdee90ebcf4f36d38471bd10681441f4e4762b9454706e81cd2b87d1186ef6619b53aa095
6
+ metadata.gz: 51d6a79615a1b7e4d191c80a3be1584f7e719f7c1907583600225c160938400ecdfac6b616440669f49c0b98bf3f36224bfb2f9a2355e94cd994be16355bfcf9
7
+ data.tar.gz: 95904bb3946944f63c6c802191dbd91b95e8d9d663a8dc2c8665ac1f94a9f863a729c27606e79be2e5cf960b6a4c8c54aa50a08be8357b6c354bf2e5522e4edd
@@ -1,28 +1,95 @@
1
1
  name: CI
2
+
2
3
  on: [push, pull_request]
4
+
3
5
  jobs:
4
- test:
5
- strategy:
6
- fail-fast: false
7
- matrix:
8
- # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
9
- ruby: [2.5, 2.6, 2.7, '3.0', head]
10
- rails: ['6.1', '6.0', '5.2']
11
- mongodb-version: ['4.4']
12
- exclude:
13
- - ruby: '3.0'
14
- rails: 5.2
15
- - ruby: head
16
- rails: 5.2
6
+ test-rails5:
17
7
  runs-on: ubuntu-latest
18
8
  steps:
19
- - uses: actions/checkout@v2
20
- - uses: supercharge/mongodb-github-action@1.6.0
9
+ - uses: actions/checkout@v5
10
+ - uses: supercharge/mongodb-github-action@1.12.0
21
11
  with:
22
- mongodb-version: ${{ matrix.mongodb-version }}
12
+ mongodb-version: "4.4"
23
13
  - uses: ruby/setup-ruby@v1
24
14
  with:
25
- ruby-version: ${{ matrix.ruby }}
26
- # bundler-cache: true # runs 'bundle install' and caches installed gems automatically
27
- - run: RAILS_VERSION=${{ matrix.rails }} bundle install
28
- - run: RAILS_VERSION=${{ matrix.rails }} bundle exec rake
15
+ ruby-version: "2.5"
16
+ - run: BUNDLE_GEMFILE=Gemfile-rails5 bundle install
17
+ - run: BUNDLE_GEMFILE=Gemfile-rails5 bundle exec rake
18
+
19
+ test-rails6_0:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v5
23
+ - uses: supercharge/mongodb-github-action@1.12.0
24
+ with:
25
+ mongodb-version: "4.4"
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: "2.6"
29
+ - run: BUNDLE_GEMFILE=Gemfile-rails6.0 bundle install
30
+ - run: BUNDLE_GEMFILE=Gemfile-rails6.0 bundle exec rake
31
+
32
+ test-rails6_1:
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v5
36
+ - uses: supercharge/mongodb-github-action@1.12.0
37
+ with:
38
+ mongodb-version: "4.4"
39
+ - uses: ruby/setup-ruby@v1
40
+ with:
41
+ ruby-version: "3.0"
42
+ - run: BUNDLE_GEMFILE=Gemfile-rails6.1 bundle install
43
+ - run: BUNDLE_GEMFILE=Gemfile-rails6.1 bundle exec rake
44
+
45
+ test-rails7_0:
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - uses: actions/checkout@v5
49
+ - uses: supercharge/mongodb-github-action@1.12.0
50
+ with:
51
+ mongodb-version: "4.4"
52
+ - uses: ruby/setup-ruby@v1
53
+ with:
54
+ ruby-version: "3.0"
55
+ - run: BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
56
+ - run: BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake
57
+
58
+ test-rails7_1:
59
+ runs-on: ubuntu-latest
60
+ steps:
61
+ - uses: actions/checkout@v5
62
+ - uses: supercharge/mongodb-github-action@1.12.0
63
+ with:
64
+ mongodb-version: "4.4"
65
+ - uses: ruby/setup-ruby@v1
66
+ with:
67
+ ruby-version: "3.2"
68
+ - run: BUNDLE_GEMFILE=Gemfile-rails7.1 bundle install
69
+ - run: BUNDLE_GEMFILE=Gemfile-rails7.1 bundle exec rake
70
+
71
+ test-rails7_2:
72
+ runs-on: ubuntu-latest
73
+ steps:
74
+ - uses: actions/checkout@v5
75
+ - uses: supercharge/mongodb-github-action@1.12.0
76
+ with:
77
+ mongodb-version: "4.4"
78
+ - uses: ruby/setup-ruby@v1
79
+ with:
80
+ ruby-version: "3.3"
81
+ - run: BUNDLE_GEMFILE=Gemfile-rails7.2 bundle install
82
+ - run: BUNDLE_GEMFILE=Gemfile-rails7.2 bundle exec rake
83
+
84
+ test-rails8:
85
+ runs-on: ubuntu-latest
86
+ steps:
87
+ - uses: actions/checkout@v5
88
+ - uses: supercharge/mongodb-github-action@1.12.0
89
+ with:
90
+ mongodb-version: "4.4"
91
+ - uses: ruby/setup-ruby@v1
92
+ with:
93
+ ruby-version: "3.3"
94
+ - run: BUNDLE_GEMFILE=Gemfile-rails8 bundle install
95
+ - run: BUNDLE_GEMFILE=Gemfile-rails8 bundle exec rake
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
3
+ /*.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.3.0
2
+
3
+ * Add `conditions` option to Reform Uniqueness validation.
4
+ * ActiveModel acceptance validation works
5
+
6
+ # 0.2.6
7
+
8
+ * Allow to override `#persisted?` and friends with modules.
9
+
1
10
  # 0.2.5
2
11
 
3
12
  * Fix: Delegating from form object causes ArgumentError with 0.2.4 (https://github.com/trailblazer/reform-rails/issues/99)
data/Gemfile-rails5 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 2.5'
5
+
6
+ gem "mongoid", "< 7.0"
7
+ gem "activerecord", "~> 5.2"
8
+ gem "railties", "~> 5.2"
9
+ gem "sqlite3", "~> 1.3", "< 1.4"
data/Gemfile-rails6.0 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 2.6'
5
+
6
+ gem "activerecord", "~> 6.0.0"
7
+ gem "railties", "~> 6.0.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/Gemfile-rails6.1 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.0'
5
+
6
+ gem "activerecord", "~> 6.1.0"
7
+ gem "railties", "~> 6.1.0"
8
+ gem "sqlite3", "~> 1.4"
9
+ gem "mongoid"
data/Gemfile-rails7.0 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.0'
5
+
6
+ gem "activerecord", "~> 7.0.0"
7
+ gem "railties", "~> 7.0.0"
8
+ gem "sqlite3", "~> 1.4"
9
+ gem "mongoid"
data/Gemfile-rails7.1 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.2'
5
+
6
+ gem "activerecord", "~> 7.1.0"
7
+ gem "railties", "~> 7.1.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/Gemfile-rails7.2 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.3'
5
+
6
+ gem "activerecord", "~> 7.2.0"
7
+ gem "railties", "~> 7.2.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/Gemfile-rails8 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.2'
5
+
6
+ gem "activerecord", "~> 8.0.0"
7
+ gem "railties", "~> 8.0.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/README.md CHANGED
@@ -28,14 +28,15 @@ Reform-rails needs Reform >= 2.3.
28
28
 
29
29
  ## Contributing
30
30
 
31
- By default your tests will run against rails 6.0.1.
32
- Please ensure that you test your changes against all supported ruby and rails versions (see .travis.yml)
31
+ Please ensure that you test your changes against all supported ruby and rails versions
33
32
 
34
33
  You can run tests for a specific version of rails by running the following:
35
34
 
36
- `export RAILS_VERSION=5.0.0; bundle update; bundle exec rake test`
35
+ ```shell
36
+ BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
37
+ BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake test
38
+ ```
37
39
 
38
40
  ## License
39
41
 
40
42
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
@@ -141,9 +141,9 @@ module Reform
141
141
  messages.to_s
142
142
  end
143
143
 
144
- def add(key, error_text)
144
+ def add(key, error_text, **error_options)
145
145
  # use rails magic to get the correct error_text and make sure we still update details and fields
146
- error = @amv_errors.add(key, error_text)
146
+ error = @amv_errors.add(key, error_text, **error_options)
147
147
  error = [error.message] unless error.is_a?(Array)
148
148
 
149
149
  # using error_text instead of text to either keep the symbol which will be
@@ -171,12 +171,12 @@ module Reform
171
171
  base_errors = @amv_errors.full_messages
172
172
  form_fields = @amv_errors.instance_variable_get(:@base).instance_variable_get(:@fields)
173
173
  nested_errors = full_messages_for_nested_fields(form_fields)
174
-
174
+
175
175
  [base_errors, nested_errors].flatten.compact
176
176
  end
177
177
 
178
178
  private
179
-
179
+
180
180
  def full_messages_for_nested_fields(form_fields)
181
181
  form_fields.map { |field| full_messages_for_twin(field[1]) }
182
182
  end
@@ -4,7 +4,11 @@ module Reform::Form::ActiveModel
4
4
  extend ClassMethods
5
5
  register_feature ActiveModel
6
6
 
7
- delegate :persisted?, :to_key, :to_param, :id, to: :model
7
+ delegations = Module.new do
8
+ delegate :persisted?, :to_key, :to_param, :id, to: :model
9
+ end
10
+
11
+ include delegations # now, those methods (e.g. {#persisted?}) can be overridden by another module.
8
12
 
9
13
  def to_model # this is called somewhere in FormBuilder and ActionController.
10
14
  self
@@ -20,7 +20,11 @@ module Reform::Form::ORM
20
20
  @klass = record.class # this is usually done in the super-sucky #setup method.
21
21
  super(record).tap do |res|
22
22
  if record.errors.present?
23
- error = self.class.name.include?("Mongoid") ? record.errors.first.last : :taken
23
+ error = if Gem::Version.new(ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
24
+ self.class.name.include?("Mongoid") ? record.errors.first.type : :taken
25
+ else
26
+ self.class.name.include?("Mongoid") ? record.errors.first.last : :taken
27
+ end
24
28
  form.errors.add(property, error)
25
29
  end
26
30
  end
@@ -14,7 +14,7 @@
14
14
  # validates :title, unique: { case_sensitive: false }
15
15
  #
16
16
  # = Scope
17
- # A scope can be use to filter the records that need to be compare with the
17
+ # A scope can be used to filter the records that need to be compare with the
18
18
  # current value to validate. A scope array can have one to many fields define.
19
19
  #
20
20
  # A scope can be define the following ways:
@@ -33,6 +33,20 @@
33
33
  # This use case is useful if album_id is set to a Song this way:
34
34
  # song = album.songs.new
35
35
  # album_id is automatically set and can't be change by the operation
36
+ #
37
+ # = Conditions
38
+ # A condition can be passed to filter the records with partial indexes
39
+ #
40
+ # Conditions can be define the following ways:
41
+ # validates :title, unique: { conditions: -> { where(archived_at: nil) } }
42
+ # - This will check that the title is unique for non archived records
43
+ # validates :title, unique: {
44
+ # conditions: ->(record) {
45
+ # published_at = record.published_at
46
+ # where(published_at: published_at.beginning_of_year..published_at.end_of_year)
47
+ # }
48
+ # }
49
+ #
36
50
 
37
51
  class Reform::Form::UniqueValidator < ActiveModel::EachValidator
38
52
  def validate_each(form, attribute, value)
@@ -57,6 +71,16 @@ class Reform::Form::UniqueValidator < ActiveModel::EachValidator
57
71
  query = query.where(field => form.send(field))
58
72
  end
59
73
 
74
+ if options[:conditions]
75
+ conditions = options[:conditions]
76
+
77
+ query = if conditions.arity.zero?
78
+ query.instance_exec(&conditions)
79
+ else
80
+ query.instance_exec(form, &conditions)
81
+ end
82
+ end
83
+
60
84
  form.errors.add(attribute, :taken) if query.count > 0
61
85
  end
62
86
  end
@@ -1,5 +1,5 @@
1
1
  module Reform
2
2
  module Rails
3
- VERSION = "0.2.5"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/lib/reform/rails.rb CHANGED
@@ -4,3 +4,29 @@ require "reform/rails/railtie"
4
4
 
5
5
  module Reform
6
6
  end
7
+
8
+ module ActiveModel
9
+ module Validations
10
+ class AcceptanceValidator < EachValidator # :nodoc:
11
+ def initialize(options)
12
+ super({ allow_nil: true, accept: ["1", true] }.merge!(options))
13
+ end
14
+
15
+ def validate_each(record, attribute, value)
16
+ unless acceptable_option?(value)
17
+ if Gem::Version.new(ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
18
+ record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
19
+ else
20
+ record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def acceptable_option?(value)
28
+ Array(options[:accept]).include?(value)
29
+ end
30
+ end
31
+ end
32
+ end
data/reform-rails.gemspec CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency "reform", ">= 2.3.1", "< 3.0.0"
24
24
  spec.add_dependency "activemodel", ">= 5.0"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "minitest-line"
27
+ spec.add_development_dependency "debug"
25
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reform-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2025-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform
@@ -44,6 +44,48 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest-line
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: debug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
47
89
  description: Automatically load and include all common Reform features for a standard
48
90
  Rails environment.
49
91
  email:
@@ -55,7 +97,13 @@ files:
55
97
  - ".github/workflows/ci.yml"
56
98
  - ".gitignore"
57
99
  - CHANGES.md
58
- - Gemfile
100
+ - Gemfile-rails5
101
+ - Gemfile-rails6.0
102
+ - Gemfile-rails6.1
103
+ - Gemfile-rails7.0
104
+ - Gemfile-rails7.1
105
+ - Gemfile-rails7.2
106
+ - Gemfile-rails8
59
107
  - LICENSE.txt
60
108
  - README.md
61
109
  - Rakefile
@@ -95,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
143
  - !ruby/object:Gem::Version
96
144
  version: '0'
97
145
  requirements: []
98
- rubygems_version: 3.4.6
146
+ rubygems_version: 3.0.3.1
99
147
  signing_key:
100
148
  specification_version: 4
101
149
  summary: Automatically load and include all common Rails form features.
data/Gemfile DELETED
@@ -1,33 +0,0 @@
1
- git_source(:github) do |repo_name|
2
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
3
- "https://github.com/#{repo_name}.git"
4
- end
5
-
6
- source "https://rubygems.org"
7
- gemspec
8
-
9
- gem 'pry-byebug'
10
- gem "minitest-line"
11
-
12
- case ENV["GEMS_SOURCE"]
13
- when "local"
14
- gem "reform", path: "../reform"
15
- when "github"
16
- gem "reform", github: "trailblazer/reform"
17
- end
18
-
19
- rails_version = ENV.fetch("RAILS_VERSION", "6.0.0")
20
-
21
- # bored of wrestling with rails...
22
-
23
- gem("mongoid", "< 7.0") unless rails_version.to_i >= 6
24
-
25
-
26
- gem "activerecord", "~> #{rails_version}"
27
- gem "railties", "~> #{rails_version}"
28
- if rails_version.to_i >= 6
29
- gem "sqlite3", "~> 1.4"
30
- else
31
- gem "sqlite3", "~> 1.3", "< 1.4"
32
- end
33
- puts "Rails version #{rails_version}"