Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ appraise "rails-6" do
gem "activesupport", "6.0.0"
gem "activerecord", "6.0.0"
end

appraise "rails-7" do
gem "activesupport", "~> 7.0.0"
gem "activerecord", "~> 7.0.0"
end
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and other niceties.

Scratching my own itch.

## Rails 6 & 7 changes

For boolean fields default value should be given as `"true"` `"false"` with quotes

## Installation

Add this line to your application's Gemfile:
Expand All @@ -40,7 +44,7 @@ Or install it yourself as:

preferences do

preference :taxable data_type: :boolean, required: true
preference :taxable data_type: :boolean, required: true, default: "true"
preference :vat_no required: false
preference :max_invoice_items data_type: :integer

Expand Down
8 changes: 8 additions & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activesupport", "~> 7.0.0"
gem "activerecord", "~> 7.0.0"

gemspec path: "../"
116 changes: 116 additions & 0 deletions gemfiles/rails_7.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
PATH
remote: ..
specs:
serial_preference (1.3.0)
activerecord (>= 6.0.0)
activesupport (>= 6.0.0)

GEM
remote: https://rubygems.org/
specs:
actionpack (7.0.4)
actionview (= 7.0.4)
activesupport (= 7.0.4)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionview (7.0.4)
activesupport (= 7.0.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (7.0.4)
activesupport (= 7.0.4)
activerecord (7.0.4)
activemodel (= 7.0.4)
activesupport (= 7.0.4)
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
appraisal (2.4.1)
bundler
rake
thor (>= 0.14.0)
builder (3.2.4)
concurrent-ruby (1.1.10)
crass (1.0.6)
diff-lcs (1.5.0)
erubi (1.12.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
method_source (1.0.0)
minitest (5.17.0)
nokogiri (1.14.0-x86_64-linux)
racc (~> 1.4)
racc (1.6.2)
rack (2.2.6)
rack-test (2.0.2)
rack (>= 1.3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.4)
loofah (~> 2.19, >= 2.19.1)
railties (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.0)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.1)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.11)
rspec-expectations (~> 3.11)
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.12.0)
shoulda (4.0.0)
shoulda-context (~> 2.0)
shoulda-matchers (~> 4.0)
shoulda-context (2.0.0)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
sqlite3 (1.6.0-x86_64-linux)
thor (1.2.1)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
zeitwerk (2.6.6)

PLATFORMS
x86_64-linux

DEPENDENCIES
activerecord (~> 7.0.0)
activesupport (~> 7.0.0)
appraisal
rspec (>= 3.0.0)
rspec-rails
serial_preference!
shoulda
sqlite3

BUNDLED WITH
2.4.3
2 changes: 1 addition & 1 deletion lib/serial_preference/has_preference_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def preference_names
private

def build_preference_definitions
serialize self._preferences_attribute, Hash
serialize self._preferences_attribute, coder: YAML, type: Hash

_preference_map.all_preference_definitions.each do |preference|

Expand Down
20 changes: 19 additions & 1 deletion lib/serial_preference/preference_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,21 @@ def value(v)
end

def column_type(type)
if greater_or_equal_rails_42?
if greater_or_equal_rails_60?
cast_type = case type
when :boolean, :integer, :float, :decimal
ActiveRecord::Type.const_get(type.to_s.titleize).new
else
ActiveRecord::Type.const_get("String").new
end
ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(
sql_type: cast_type.type.to_s,
type: cast_type.type,
limit: cast_type.limit,
precision: cast_type.precision,
scale: cast_type.scale
)
elsif greater_or_equal_rails_42?
case type
when :boolean
ActiveRecord::Type::Boolean.new
Expand All @@ -101,5 +115,9 @@ def column_type(type)
def greater_or_equal_rails_42?
ActiveRecord::VERSION::MAJOR > 4 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2)
end

def greater_or_equal_rails_60?
ActiveRecord::VERSION::MAJOR > 6 || (ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR >= 0)
end
end
end
2 changes: 1 addition & 1 deletion lib/serial_preference/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SerialPreference
VERSION = "1.3.0"
VERSION = "1.3.3"
end
2 changes: 1 addition & 1 deletion spec/fixtures/dummy_class.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DummyClass < ActiveRecord::Base
include SerialPreference::HasSerialPreferences
preferences do
preference :taxable, data_type: :boolean, required: true, default: true
preference :taxable, data_type: :boolean, required: true, default: "true"
preference :required_number, data_type: :integer, required: :true
preference :vat_no, required: false
preference :max_invoice_items, data_type: :integer
Expand Down