From 7d7c1281208d6fc4953e9b02d136af7a353fad7d Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Wed, 18 Dec 2024 22:28:39 -0600 Subject: [PATCH 1/2] Upgrade ruby version to 2.7 and replace deprecated factory_girl to factory_bot --- .ruby-version | 2 +- restpack_serializer.gemspec | 2 +- spec/serializable/paging_spec.rb | 8 +++---- spec/serializable/resource_spec.rb | 4 ++-- spec/serializable/serializer_spec.rb | 6 ++--- .../side_loading/belongs_to_spec.rb | 6 ++--- .../side_loading/has_and_belongs_many_spec.rb | 4 ++-- .../side_loading/has_many_spec.rb | 8 +++---- .../side_loading/side_loading_spec.rb | 4 ++-- spec/serializable/single_spec.rb | 2 +- spec/spec_helper.rb | 4 ++-- spec/support/factory.rb | 24 ++++++++++--------- 12 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.ruby-version b/.ruby-version index 5154b3f..1effb00 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6 +2.7 diff --git a/restpack_serializer.gemspec b/restpack_serializer.gemspec index bc7d8cb..40e1246 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', '~> 10.0.3' gem.add_development_dependency 'guard-rspec', '~> 2.5.4' - gem.add_development_dependency 'factory_girl' + gem.add_development_dependency 'factory_bot', '6.4.4' gem.add_development_dependency 'sqlite3', '< 1.6' gem.add_development_dependency 'database_cleaner', '~> 1.0.1' gem.add_development_dependency 'rspec' diff --git a/spec/serializable/paging_spec.rb b/spec/serializable/paging_spec.rb index 8a3b38c..43ddb01 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 @@ -225,8 +225,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 814756e..021b0d9 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 @@ -49,7 +49,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 754d49f..3e94a9f 100644 --- a/spec/serializable/serializer_spec.rb +++ b/spec/serializable/serializer_spec.rb @@ -143,7 +143,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) json[:links].should == { artist: @album1.artist_id.to_s, @@ -154,7 +154,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 } } @@ -179,7 +179,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 d69878d..62b7f7f 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) } @@ -80,7 +80,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 f4bd05b..8372a1a 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 3aaf33f..60c3252 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 @@ -58,8 +58,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 ec890b5..925df82 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 e316bb0..be6b311 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 5a2e6f3..0da5204 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,10 +7,10 @@ require 'database_cleaner' require 'coveralls' Coveralls.wear! -FactoryGirl.find_definitions +FactoryBot.find_definitions RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods + config.include FactoryBot::Syntax::Methods config.before(:suite) do DatabaseCleaner.clean_with(:truncation) diff --git a/spec/support/factory.rb b/spec/support/factory.rb index 40d0f5e..e5baf9a 100644 --- a/spec/support/factory.rb +++ b/spec/support/factory.rb @@ -1,13 +1,13 @@ -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/" } factory :artist_with_albums do - ignore do - album_count 3 + transient do + album_count { 3 } end after(:create) do |artist, evaluator| @@ -16,18 +16,20 @@ end factory :artist_with_fans do - ignore do - fans_count 3 + transient do + fans_count { 3 } end + after(:create) do |artist, evaluator| create_list(:payment, evaluator.fans_count, artist: artist) end end factory :artist_with_stalkers do - ignore do - stalker_count 2 + transient do + stalker_count { 2 } end + after(:create) do |artist, evaluator| create_list(:stalker, evaluator.stalker_count, artists: [ artist ]) end @@ -40,8 +42,8 @@ artist factory :album_with_songs do - ignore do - song_count 10 + transient do + song_count { 10 } end after(:create) do |album, evaluator| @@ -57,7 +59,7 @@ end factory :payment, :class => MyApp::Payment do - amount 999 + amount { 999 } artist fan end From 63bbd6d0b8db33c61277eec1f987034b16d7d907 Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Wed, 18 Dec 2024 22:29:23 -0600 Subject: [PATCH 2/2] Update run_tests_CI.yml --- .github/workflows/run_tests_CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests_CI.yml b/.github/workflows/run_tests_CI.yml index 836810e..f702db2 100644 --- a/.github/workflows/run_tests_CI.yml +++ b/.github/workflows/run_tests_CI.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6'] + ruby-version: ['2.7'] steps: - uses: actions/checkout@v4