Skip to content

Commit

Permalink
add Ruby 3.2, activesupport 7.1 support (#161)
Browse files Browse the repository at this point in the history
* drop Ruby 2.7
* add Ruby 3.2
* drop activesupport 6.x
* add activesupport 7.1
  • Loading branch information
langalex authored Jan 18, 2024
1 parent a185a80 commit 50df683
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 79 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.7, "3.0", "3.1", "jruby"]
ruby: ["3.0", "3.1", "3.2", "jruby"]
gemfile:
- "active_support_6_0"
- "active_support_6_1"
- "active_support_7_0"
- "active_support_7_1"
exclude:
- ruby: "jruby"
gemfile: "active_support_7_0"
- ruby: "3.0"
gemfile: "active_support_6_0"
- ruby: "3.1"
gemfile: "active_support_6_0"
steps:
- uses: actions/checkout@v2
- name: Set up CouchDB
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ end

desc 'Run all specs for all gemfiles'
task :spec do
%w(7_0 6_1 6_0 5_2 5_1 5_0).each do |version|
Bundler.with_clean_env do
%w(7_1 7_0).each do |version|
Bundler.with_original_env do
puts "Running tests with ActiveSupport #{version.sub('_', '.')}"
sh "env BUNDLE_GEMFILE=gemfiles/active_support_#{version} bundle install"
sh "env BUNDLE_GEMFILE=gemfiles/active_support_#{version} bundle exec rake spec_unit spec_functional"
Expand Down
4 changes: 2 additions & 2 deletions couch_potato.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Gem::Specification.new do |s|
s.version = CouchPotato::VERSION
s.platform = Gem::Platform::RUBY

s.add_dependency 'activemodel', ['>= 5.0', '< 7.1']
s.add_dependency 'activemodel', ['>= 5.0', '< 8.0']
s.add_dependency 'couchrest', '~>2.0.0'
s.add_dependency 'json', '~> 2.3'

s.add_development_dependency 'rake', '~>12.0'
s.add_development_dependency 'rspec', '~>3.10.0'
s.add_development_dependency 'rspec', '~>3.12.0'
s.add_development_dependency 'timecop'
s.add_development_dependency 'tzinfo'

Expand Down
7 changes: 0 additions & 7 deletions gemfiles/active_support_6_0

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/active_support_7_0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'railties', '~>7.0.4'
gem 'railties', '~>7.0.8'
gem 'activemodel'
gem 'execjs'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'railties', '~>6.1'
gem 'railties', '~>7.1.3'
gem 'activemodel'
gem 'execjs'

Expand Down
6 changes: 5 additions & 1 deletion lib/couch_potato/persistence/properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def property(name, options = {})
active_support_module.module_eval do
undef_method(name) if instance_methods.include?(name)
end
cache = send(:attribute_method_matchers_cache)
cache = if respond_to?(:attribute_method_matchers_cache, true) # activemodel 7.0
send(:attribute_method_matchers_cache)
else # activemodel 7.1
send(:attribute_method_patterns_cache)
end
cache.delete(name)

define_attribute_method name
Expand Down
2 changes: 1 addition & 1 deletion lib/couch_potato/persistence/type_caster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def cast_boolean(value)
def cast_native(value, type)
if type && !value.is_a?(type)

if %w[Integer Bignum Fixnum].include?(type.to_s)
if %w[Integer Bignum].include?(type.to_s)
value.to_s.scan(NUMBER_REGEX).join.to_d.round unless value.blank?
elsif type == Float
value.to_s.scan(NUMBER_REGEX).join.to_f unless value.blank?
Expand Down
62 changes: 5 additions & 57 deletions spec/unit/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Branch
class Plant
include CouchPotato::Persistence
property :leaf_count
property :typed_leaf_count, type: Fixnum
property :integer_something, type: Integer
property :typed_leaf_size, type: Float
property :branch, type: Branch
Expand Down Expand Up @@ -42,7 +41,7 @@ class SpecialPlant < Plant

expect(plant.attributes).to eq('leaf_count' => 1, 'created_at' => nil,
'integer_something' => nil,
'updated_at' => nil, 'typed_leaf_count' => nil,
'updated_at' => nil,
'typed_leaf_size' => nil, 'branch' => nil)
end

Expand Down Expand Up @@ -112,25 +111,25 @@ class SpecialPlant < Plant
end

describe 'integer' do
it 'rounds a float to a fixnum' do
it 'rounds a float to an integer' do
@plant.integer_something = 4.5

expect(@plant.integer_something).to eq(5)
end

it 'converts a string into a fixnum' do
it 'converts a string into an integer' do
@plant.integer_something = '4'

expect(@plant.integer_something).to eq(4)
end

it 'converts a string into a negative fixnum' do
it 'converts a string into a negative integer' do
@plant.integer_something = '-4'

expect(@plant.integer_something).to eq(-4)
end

it 'leaves a fixnum as is' do
it 'leaves an integer as is' do
@plant.integer_something = 4

expect(@plant.integer_something).to eq(4)
Expand Down Expand Up @@ -161,57 +160,6 @@ class SpecialPlant < Plant
end
end


describe 'fixnum' do
it 'rounds a float to a fixnum' do
@plant.typed_leaf_count = 4.5

expect(@plant.typed_leaf_count).to eq(5)
end

it 'converts a string into a fixnum' do
@plant.typed_leaf_count = '4'

expect(@plant.typed_leaf_count).to eq(4)
end

it 'converts a string into a negative fixnum' do
@plant.typed_leaf_count = '-4'

expect(@plant.typed_leaf_count).to eq(-4)
end

it 'leaves a fixnum as is' do
@plant.typed_leaf_count = 4

expect(@plant.typed_leaf_count).to eq(4)
end

it 'leaves nil as is' do
@plant.typed_leaf_count = nil

expect(@plant.typed_leaf_count).to be_nil
end

it 'sets the attributes to zero if a string given' do
@plant.typed_leaf_count = 'x'

expect(@plant.typed_leaf_count).to eq(0)
end

it 'parses numbers out of a string' do
@plant.typed_leaf_count = 'x123'

expect(@plant.typed_leaf_count).to eq(123)
end

it 'sets the attributes to nil if given a blank string' do
@plant.typed_leaf_count = ''

expect(@plant.typed_leaf_count).to be_nil
end
end

context 'float' do
it 'converts a number in a string with a decimal place' do
@plant.typed_leaf_size = '0.5001'
Expand Down

0 comments on commit 50df683

Please sign in to comment.