Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ruby version to 2.7 and replace deprecated factory_girl to factory_bot #6

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6']
ruby-version: ['2.7']

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6
2.7
2 changes: 1 addition & 1 deletion restpack_serializer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions spec/serializable/paging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions spec/serializable/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/serializable/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 } }
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/serializable/side_loading/belongs_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/serializable/side_loading/has_and_belongs_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/serializable/side_loading/has_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]}
Expand Down
4 changes: 2 additions & 2 deletions spec/serializable/side_loading/side_loading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion spec/serializable/single_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 13 additions & 11 deletions spec/support/factory.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand All @@ -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
Expand All @@ -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|
Expand All @@ -57,7 +59,7 @@
end

factory :payment, :class => MyApp::Payment do
amount 999
amount { 999 }
artist
fan
end
Expand Down
Loading