From e46f5270d8a5eac855d9ba09954fa781d98852ad Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 5 Jun 2025 12:36:50 +0100 Subject: [PATCH 1/7] Add support for Rails 7.2 and Rails 8.0 --- restpack_serializer.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restpack_serializer.gemspec b/restpack_serializer.gemspec index 5c7b60c..cc61599 100644 --- a/restpack_serializer.gemspec +++ b/restpack_serializer.gemspec @@ -17,8 +17,8 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] - gem.add_dependency 'activesupport', ['>= 4.0.3', '< 7.2'] - gem.add_dependency 'activerecord', ['>= 4.0.3', '< 7.2'] + gem.add_dependency 'activesupport', ['>= 4.0.3', '< 8.1'] + gem.add_dependency 'activerecord', ['>= 4.0.3', '< 8.1'] gem.add_dependency 'kaminari', ['>= 0.17.0', '< 2.0'] gem.add_development_dependency 'restpack_gem', '~> 0.0.9' From 6ce098265c2fa7397697d35c88ba3c6f446c52e6 Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 12 Jun 2025 00:49:33 +0100 Subject: [PATCH 2/7] Use factory_bot instead of factory_girl --- restpack_serializer.gemspec | 2 +- spec/serializable/paging_spec.rb | 8 ++++---- spec/serializable/resource_spec.rb | 4 ++-- spec/serializable/serializer_spec.rb | 6 +++--- spec/serializable/side_loading/belongs_to_spec.rb | 6 +++--- .../side_loading/has_and_belongs_many_spec.rb | 4 ++-- spec/serializable/side_loading/has_many_spec.rb | 8 ++++---- spec/serializable/side_loading/side_loading_spec.rb | 4 ++-- spec/serializable/single_spec.rb | 2 +- spec/spec_helper.rb | 4 ++-- spec/support/factory.rb | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/restpack_serializer.gemspec b/restpack_serializer.gemspec index cc61599..36ddd34 100644 --- a/restpack_serializer.gemspec +++ b/restpack_serializer.gemspec @@ -24,8 +24,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'restpack_gem', '~> 0.0.9' gem.add_development_dependency 'rake', '~> 13' gem.add_development_dependency 'guard-rspec', '~> 4.7' - gem.add_development_dependency 'factory_girl', '~> 4.7' gem.add_development_dependency 'sqlite3', '~> 1.3' + gem.add_development_dependency 'factory_bot', '~> 4.8' gem.add_development_dependency 'database_cleaner' gem.add_development_dependency 'rspec' gem.add_development_dependency 'bump' diff --git a/spec/serializable/paging_spec.rb b/spec/serializable/paging_spec.rb index ba1ffbf..60d9f91 100644 --- a/spec/serializable/paging_spec.rb +++ b/spec/serializable/paging_spec.rb @@ -2,8 +2,8 @@ describe RestPack::Serializer::Paging do before(:each) do - @album1 = FactoryGirl.create(:album_with_songs, song_count: 11) - @album2 = FactoryGirl.create(:album_with_songs, song_count: 7) + @album1 = FactoryBot.create(:album_with_songs, song_count: 11) + @album2 = FactoryBot.create(:album_with_songs, song_count: 7) end context "#page" do @@ -229,8 +229,8 @@ context "with custom scope" do before do - FactoryGirl.create(:album, year: 1930) - FactoryGirl.create(:album, year: 1948) + FactoryBot.create(:album, year: 1930) + FactoryBot.create(:album, year: 1948) end let(:page) { MyApp::AlbumSerializer.page(params, scope) } let(:scope) { MyApp::Album.classic } diff --git a/spec/serializable/resource_spec.rb b/spec/serializable/resource_spec.rb index 55177a7..2fd358b 100644 --- a/spec/serializable/resource_spec.rb +++ b/spec/serializable/resource_spec.rb @@ -2,7 +2,7 @@ describe RestPack::Serializer::Resource do before(:each) do - @album = FactoryGirl.create(:album_with_songs, song_count: 11) + @album = FactoryBot.create(:album_with_songs, song_count: 11) @song = @album.songs.first end @@ -50,7 +50,7 @@ end describe "song with no artist" do - let(:song) { FactoryGirl.create(:song, artist: nil) } + let(:song) { FactoryBot.create(:song, artist: nil) } let(:resource) { MyApp::SongSerializer.resource(id: song.id.to_s) } it "should not have an artist link" do diff --git a/spec/serializable/serializer_spec.rb b/spec/serializable/serializer_spec.rb index e5238e0..d11416a 100644 --- a/spec/serializable/serializer_spec.rb +++ b/spec/serializable/serializer_spec.rb @@ -266,7 +266,7 @@ def custom_attributes let(:serializer) { MyApp::SongSerializer.new } it "includes 'links' data for :belongs_to associations" do - @album1 = FactoryGirl.create(:album_with_songs, song_count: 11) + @album1 = FactoryBot.create(:album_with_songs, song_count: 11) json = serializer.as_json(@album1.songs.first) expect(json[:links]).to eq( artist: @album1.artist_id.to_s, @@ -276,7 +276,7 @@ def custom_attributes end context "with a serializer with has_* associations" do - let(:artist_factory) { FactoryGirl.create :artist_with_fans } + let(:artist_factory) { FactoryBot.create :artist_with_fans } let(:artist_serializer) { MyApp::ArtistSerializer.new } let(:json) { artist_serializer.as_json(artist_factory) } let(:side_load_ids) { artist_has_association.map { |obj| obj.id.to_s } } @@ -302,7 +302,7 @@ def custom_attributes end describe "'has_and_belongs_to_many' associations" do - let(:artist_factory) { FactoryGirl.create :artist_with_stalkers } + let(:artist_factory) { FactoryBot.create :artist_with_stalkers } let(:artist_has_association) { artist_factory.stalkers } it "includes 'links' data when there are associated records" do diff --git a/spec/serializable/side_loading/belongs_to_spec.rb b/spec/serializable/side_loading/belongs_to_spec.rb index 899546a..b7b3a89 100644 --- a/spec/serializable/side_loading/belongs_to_spec.rb +++ b/spec/serializable/side_loading/belongs_to_spec.rb @@ -5,8 +5,8 @@ describe ".belongs_to" do before(:each) do - FactoryGirl.create(:artist_with_albums, album_count: 2) - FactoryGirl.create(:artist_with_albums, album_count: 1) + FactoryBot.create(:artist_with_albums, album_count: 2) + FactoryBot.create(:artist_with_albums, album_count: 1) end let(:side_loads) { MyApp::SongSerializer.side_loads(models, options) } @@ -68,7 +68,7 @@ end context 'without an associated model' do - let!(:b_side) { FactoryGirl.create(:song, album: nil) } + let!(:b_side) { FactoryBot.create(:song, album: nil) } let(:models) { [b_side] } context 'when including :albums' do diff --git a/spec/serializable/side_loading/has_and_belongs_many_spec.rb b/spec/serializable/side_loading/has_and_belongs_many_spec.rb index f67603e..7d2de01 100644 --- a/spec/serializable/side_loading/has_and_belongs_many_spec.rb +++ b/spec/serializable/side_loading/has_and_belongs_many_spec.rb @@ -7,8 +7,8 @@ describe ".has_and_belongs_to_many" do before(:each) do - @artist1 = FactoryGirl.create(:artist_with_stalkers, stalker_count: 2) - @artist2 = FactoryGirl.create(:artist_with_stalkers, stalker_count: 3) + @artist1 = FactoryBot.create(:artist_with_stalkers, stalker_count: 2) + @artist2 = FactoryBot.create(:artist_with_stalkers, stalker_count: 3) end context "with a single model" do diff --git a/spec/serializable/side_loading/has_many_spec.rb b/spec/serializable/side_loading/has_many_spec.rb index 9a24ef2..8b7492d 100644 --- a/spec/serializable/side_loading/has_many_spec.rb +++ b/spec/serializable/side_loading/has_many_spec.rb @@ -7,8 +7,8 @@ describe ".has_many" do before(:each) do - @artist1 = FactoryGirl.create(:artist_with_albums, album_count: 2) - @artist2 = FactoryGirl.create(:artist_with_albums, album_count: 1) + @artist1 = FactoryBot.create(:artist_with_albums, album_count: 2) + @artist2 = FactoryBot.create(:artist_with_albums, album_count: 1) end context "with a single model" do @@ -43,8 +43,8 @@ describe '.has_many through' do context 'when including :fans' do let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "fans") } - let(:artist_1) { FactoryGirl.create :artist_with_fans } - let(:artist_2) { FactoryGirl.create :artist_with_fans } + let(:artist_1) { FactoryBot.create :artist_with_fans } + let(:artist_2) { FactoryBot.create :artist_with_fans } context "with a single model" do let(:models) { [artist_1] } diff --git a/spec/serializable/side_loading/side_loading_spec.rb b/spec/serializable/side_loading/side_loading_spec.rb index 8b10e0d..e666ccb 100644 --- a/spec/serializable/side_loading/side_loading_spec.rb +++ b/spec/serializable/side_loading/side_loading_spec.rb @@ -3,7 +3,7 @@ describe RestPack::Serializer::SideLoading do context "invalid :include" do before(:each) do - FactoryGirl.create(:song) + FactoryBot.create(:song) end context "an include to an inexistent model" do @@ -19,7 +19,7 @@ context "an include to a model which has not been whitelisted with 'can_include'" do it "raises an exception" do - payment = FactoryGirl.create(:payment) + payment = FactoryBot.create(:payment) exception = RestPack::Serializer::InvalidInclude message = ":payments is not a valid include for MyApp::Artist" diff --git a/spec/serializable/single_spec.rb b/spec/serializable/single_spec.rb index b82e406..30c8f92 100644 --- a/spec/serializable/single_spec.rb +++ b/spec/serializable/single_spec.rb @@ -2,7 +2,7 @@ describe RestPack::Serializer::Single do before(:each) do - @album = FactoryGirl.create(:album_with_songs, song_count: 11) + @album = FactoryBot.create(:album_with_songs, song_count: 11) @song = @album.songs.first end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fdd0a23..fcc9e9a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,10 +9,10 @@ Coveralls::Output.silent = true unless ENV["CI"] Coveralls.wear! -FactoryGirl.find_definitions +FactoryBot.find_definitions RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods + config.include FactoryBot::Syntax::Methods config.raise_errors_for_deprecations! config.before(:suite) do diff --git a/spec/support/factory.rb b/spec/support/factory.rb index 8f43ef6..ca5e134 100644 --- a/spec/support/factory.rb +++ b/spec/support/factory.rb @@ -1,6 +1,6 @@ -require 'factory_girl' +require 'factory_bot' -FactoryGirl.define do +FactoryBot.define do factory :artist, class: MyApp::Artist do sequence(:name) { |n| "Artist ##{n}" } sequence(:website) { |n| "http://website#{n}.com/" } From 4effc236c5d8b3aec368c102712f82e832fc8a36 Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 12 Jun 2025 00:50:58 +0100 Subject: [PATCH 3/7] Update sqlite3 version Rails 7.2 expects sqlite 3 > 2.1 https://github.com/rails/rails/blob/v8.0.2/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14 --- restpack_serializer.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restpack_serializer.gemspec b/restpack_serializer.gemspec index 36ddd34..d1ce8e0 100644 --- a/restpack_serializer.gemspec +++ b/restpack_serializer.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'restpack_gem', '~> 0.0.9' gem.add_development_dependency 'rake', '~> 13' gem.add_development_dependency 'guard-rspec', '~> 4.7' - gem.add_development_dependency 'sqlite3', '~> 1.3' + gem.add_development_dependency 'sqlite3', '~> 2.1' gem.add_development_dependency 'factory_bot', '~> 4.8' gem.add_development_dependency 'database_cleaner' gem.add_development_dependency 'rspec' From 34dd20ab6e8963607e8f95e5011ed097f87b7fa2 Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 12 Jun 2025 11:07:17 +0100 Subject: [PATCH 4/7] pin sqlite3 for ruby < 3.1 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 82c279b..e46745a 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem 'memory_profiler', require: false if RUBY_VERSION < "2.2" gem "sqlite3", "~> 1.3.0" -elsif RUBY_VERSION < "2.5" +elsif RUBY_VERSION < "3.1" gem "sqlite3", "~> 1.4.0" gem "term-ansicolor", "< 1.10.3" elsif RUBY_VERSION >= "3.4" From 315333acbb290d78d749a8efbf93a892d3221140 Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 12 Jun 2025 11:29:11 +0100 Subject: [PATCH 5/7] Bump factory_bot_rails To get rid of another ActiveSupport::Deprecation:Class warn method deprecated --- restpack_serializer.gemspec | 2 +- spec/support/factory.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/restpack_serializer.gemspec b/restpack_serializer.gemspec index d1ce8e0..4c9b6c5 100644 --- a/restpack_serializer.gemspec +++ b/restpack_serializer.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rake', '~> 13' gem.add_development_dependency 'guard-rspec', '~> 4.7' gem.add_development_dependency 'sqlite3', '~> 2.1' - gem.add_development_dependency 'factory_bot', '~> 4.8' + gem.add_development_dependency 'factory_bot_rails', '~> 5.0' gem.add_development_dependency 'database_cleaner' gem.add_development_dependency 'rspec' gem.add_development_dependency 'bump' diff --git a/spec/support/factory.rb b/spec/support/factory.rb index ca5e134..1fd508e 100644 --- a/spec/support/factory.rb +++ b/spec/support/factory.rb @@ -6,7 +6,7 @@ sequence(:website) { |n| "http://website#{n}.com/" } factory :artist_with_albums do - transient { album_count 3 } + transient { album_count { 3 } } after(:create) do |artist, evaluator| create_list(:album_with_songs, evaluator.album_count, artist: artist) @@ -14,7 +14,7 @@ end factory :artist_with_fans do - transient { fans_count 3 } + transient { fans_count { 3 } } after(:create) do |artist, evaluator| create_list(:payment, evaluator.fans_count, artist: artist) @@ -22,7 +22,7 @@ end factory :artist_with_stalkers do - transient { stalker_count 2 } + transient { stalker_count { 2 } } after(:create) do |artist, evaluator| create_list(:stalker, evaluator.stalker_count, artists: [artist]) @@ -36,7 +36,7 @@ artist factory :album_with_songs do - transient { song_count 10 } + transient { song_count { 10 } } after(:create) do |album, evaluator| create_list(:song, evaluator.song_count, album: album, artist: album.artist) @@ -51,7 +51,7 @@ end factory :payment, class: MyApp::Payment do - amount 999 + amount { 999 } artist fan end From c41af11301bd42cf25bcbc4a61ce13bfceb5a50d Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 12 Jun 2025 11:31:44 +0100 Subject: [PATCH 6/7] Require logger earlier --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fcc9e9a..ffba060 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'rspec' -require './lib/restpack_serializer' require 'logger' +require './lib/restpack_serializer' require './spec/fixtures/db' require './spec/fixtures/serializers' require './spec/support/factory' From 32b907ef1846940e2bc5b09abeefb2a42dd66c35 Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Thu, 12 Jun 2025 18:51:24 +0100 Subject: [PATCH 7/7] Update restpack_serializer.gemspec Co-authored-by: Eugene Kenny --- restpack_serializer.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restpack_serializer.gemspec b/restpack_serializer.gemspec index 4c9b6c5..bc272fc 100644 --- a/restpack_serializer.gemspec +++ b/restpack_serializer.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rake', '~> 13' gem.add_development_dependency 'guard-rspec', '~> 4.7' gem.add_development_dependency 'sqlite3', '~> 2.1' - gem.add_development_dependency 'factory_bot_rails', '~> 5.0' + gem.add_development_dependency 'factory_bot', '~> 5.0' gem.add_development_dependency 'database_cleaner' gem.add_development_dependency 'rspec' gem.add_development_dependency 'bump'