From 7ce4ad2cdba383becb09de3371ea2554e18b0587 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Thu, 29 Aug 2019 17:00:13 +0900 Subject: [PATCH 1/5] Throw :abort instead of returning false while before_save Closes: #132 Signed-off-by: Jongmin Kim --- spec/spec_helper.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e145932..2eccff5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,7 +35,13 @@ class SeededModel < ActiveRecord::Base attr_protected :first_name if self.respond_to?(:protected_attributes) attr_accessor :fail_to_save - before_save { false if fail_to_save } + # From Rails 5.1, returning 'false' will not implicitly halt a callback chain. + # It was deprecated from Rails 5.0. + if ActiveRecord::VERSION::MAJOR < 5 + before_save { false if fail_to_save } + else + before_save { throw :abort if fail_to_save } + end end class SeededModelNoPrimaryKey < ActiveRecord::Base From 96a307f7927a290d7d7104fa8513b73b2de72857 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Thu, 29 Aug 2019 22:14:36 +0900 Subject: [PATCH 2/5] Allow Rails 6 in Gemfile Signed-off-by: Jongmin Kim --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 199be03..e0fd083 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'http://rubygems.org' -gem 'rails', ">= 3.1", "< 5.1" +gem 'rails', ">= 3.1", "< 6.1" gemspec From 56f9133fa4ba2fcb7de12d2348b33ea48cc0639b Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Thu, 29 Aug 2019 22:44:10 +0900 Subject: [PATCH 3/5] Replace RSpec syntax "should" with "expect" `:should` syntax without explicitly enabling the syntax is deprecated in RSpec. This patch will replace `:should` syntax with `#expect`, which introduced in RSpec 2.11. mbleigh/seed-fu#136 Signed-off-by: Jongmin Kim --- spec/runner_spec.rb | 12 ++++++------ spec/seeder_spec.rb | 40 ++++++++++++++++++++-------------------- spec/writer_spec.rb | 10 +++++----- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 85f1581..79052db 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -4,21 +4,21 @@ it "should seed data from Ruby and gzipped Ruby files in the given fixtures directory" do SeedFu.seed(File.dirname(__FILE__) + '/fixtures') - SeededModel.find(1).title.should == "Foo" - SeededModel.find(2).title.should == "Bar" - SeededModel.find(3).title.should == "Baz" + expect(SeededModel.find(1).title).to eq("Foo") + expect(SeededModel.find(2).title).to eq("Bar") + expect(SeededModel.find(3).title).to eq("Baz") end it "should seed only the data which matches the filter, if one is given" do SeedFu.seed(File.dirname(__FILE__) + '/fixtures', /_2/) - SeededModel.count.should == 1 - SeededModel.find(2).title.should == "Bar" + expect(SeededModel.count).to eq(1) + expect(SeededModel.find(2).title).to eq("Bar") end it "should use the SpecFu.fixtures_path variable to determine where fixtures are" do SeedFu.fixture_paths = [File.dirname(__FILE__) + '/fixtures'] SeedFu.seed - SeededModel.count.should == 3 + expect(SeededModel.count).to eq(3) end end diff --git a/spec/seeder_spec.rb b/spec/seeder_spec.rb index 0b4e009..b940b39 100644 --- a/spec/seeder_spec.rb +++ b/spec/seeder_spec.rb @@ -20,12 +20,12 @@ end bob = SeededModel.find_by_id(-2) - bob.first_name.should == "Bob" - bob.last_name.should == "Bobson" + expect(bob.first_name).to eq("Bob") + expect(bob.last_name).to eq("Bobson") if ENV['DB'] == 'postgresql' next_id = SeededModel.connection.execute("select nextval('seeded_models_id_seq')") - next_id[0]['nextval'].to_i.should == 11 + expect(next_id[0]['nextval'].to_i).to eq(11) end end @@ -39,8 +39,8 @@ end bob = SeededModel.find_by_id(5) - bob.first_name.should == "Bob" - bob.last_name.should == "Bobson" + expect(bob.first_name).to eq("Bob") + expect(bob.last_name).to eq("Bobson") end it "should be able to handle multiple constraints" do @@ -50,7 +50,7 @@ s.first_name = "Bob" end - SeededModel.count.should == 1 + expect(SeededModel.count).to eq(1) SeededModel.seed(:title, :login) do |s| s.login = "frank" @@ -58,15 +58,15 @@ s.first_name = "Frank" end - SeededModel.count.should == 2 + expect(SeededModel.count).to eq(2) - SeededModel.find_by_login("bob").first_name.should == "Bob" + expect(SeededModel.find_by_login("bob").first_name).to eq("Bob") SeededModel.seed(:title, :login) do |s| s.login = "bob" s.title = "Peon" s.first_name = "Steve" end - SeededModel.find_by_login("bob").first_name.should == "Steve" + expect(SeededModel.find_by_login("bob").first_name).to eq("Steve") end it "should be able to create models from an array of seed attributes" do @@ -76,9 +76,9 @@ {:login => "harry", :title => "Noble", :first_name => "Harry"} ]) - SeededModel.find_by_login("bob").first_name.should == "Steve" - SeededModel.find_by_login("frank").first_name.should == "Francis" - SeededModel.find_by_login("harry").first_name.should == "Harry" + expect(SeededModel.find_by_login("bob").first_name).to eq("Steve") + expect(SeededModel.find_by_login("frank").first_name).to eq("Francis") + expect(SeededModel.find_by_login("harry").first_name).to eq("Harry") end it "should be able to create models from a list of seed attribute hashes at the end of the args" do @@ -88,9 +88,9 @@ {:login => "harry", :title => "Noble", :first_name => "Harry"} ) - SeededModel.find_by_login("bob").first_name.should == "Steve" - SeededModel.find_by_login("frank").first_name.should == "Francis" - SeededModel.find_by_login("harry").first_name.should == "Harry" + expect(SeededModel.find_by_login("bob").first_name).to eq("Steve") + expect(SeededModel.find_by_login("frank").first_name).to eq("Francis") + expect(SeededModel.find_by_login("harry").first_name).to eq("Harry") end it "should update, not create, if constraints are met" do @@ -111,8 +111,8 @@ end bob = SeededModel.find_by_id(1) - bob.first_name.should == "Robert" - bob.last_name.should == "Bobson" + expect(bob.first_name).to eq("Robert") + expect(bob.last_name).to eq("Bobson") end it "should create but not update with seed_once" do @@ -133,15 +133,15 @@ end bob = SeededModel.find_by_id(1) - bob.first_name.should == "Bob" - bob.last_name.should == "Bobson" + expect(bob.first_name).to eq("Bob") + expect(bob.last_name).to eq("Bobson") end it "should default to an id constraint" do SeededModel.seed(:title => "Bla", :id => 1) SeededModel.seed(:title => "Foo", :id => 1) - SeededModel.find(1).title.should == "Foo" + expect(SeededModel.find(1).title).to eq("Foo") end it "should require that all constraints are defined" do diff --git a/spec/writer_spec.rb b/spec/writer_spec.rb index 24eb7ed..06540aa 100644 --- a/spec/writer_spec.rb +++ b/spec/writer_spec.rb @@ -16,8 +16,8 @@ end load @file_name - SeededModel.find(1).title.should == "Mr" - SeededModel.find(2).title.should == "Dr" + expect(SeededModel.find(1).title).to eq("Mr") + expect(SeededModel.find(2).title).to eq("Dr") end it "should support chunking" do @@ -28,8 +28,8 @@ end load @file_name - SeededModel.count.should == 3 - File.read(@file_name).should include("# BREAK EVAL\n") + expect(SeededModel.count).to eq(3) + expect(File.read(@file_name)).to include("# BREAK EVAL\n") end it "should support specifying the output to use 'seed_once' rather than 'seed'" do @@ -40,6 +40,6 @@ end load @file_name - SeededModel.find(1).title.should == "Dr" + expect(SeededModel.find(1).title).to eq("Dr") end end From e68b051797071760353aeb98a70b23ab0cab787b Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Thu, 29 Aug 2019 22:46:00 +0900 Subject: [PATCH 4/5] Limit the RSpec to >= 2.11 and < 4.0 Closes: mbleigh/seed-fu#136 Signed-off-by: Jongmin Kim --- seed-fu.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed-fu.gemspec b/seed-fu.gemspec index 520680b..6213114 100644 --- a/seed-fu.gemspec +++ b/seed-fu.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_dependency "activerecord", [">= 3.1"] s.add_dependency "activesupport", [">= 3.1"] - s.add_development_dependency "rspec", "~> 2.0" + s.add_development_dependency "rspec", [">= 2.11", "< 4.0"] s.add_development_dependency "pg", '~> 0' s.add_development_dependency "mysql2", '~> 0' s.add_development_dependency "sqlite3", '~> 0' From 0cd6f38d2603eceb5dc8934e0ca6a2411ac2eac4 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Thu, 29 Aug 2019 22:57:44 +0900 Subject: [PATCH 5/5] Remove the version limitation for sqlite3 Signed-off-by: Jongmin Kim --- seed-fu.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed-fu.gemspec b/seed-fu.gemspec index 6213114..867c2e9 100644 --- a/seed-fu.gemspec +++ b/seed-fu.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", [">= 2.11", "< 4.0"] s.add_development_dependency "pg", '~> 0' s.add_development_dependency "mysql2", '~> 0' - s.add_development_dependency "sqlite3", '~> 0' + s.add_development_dependency "sqlite3" s.files = Dir.glob("{lib}/**/*") + %w(LICENSE README.md CHANGELOG.md) s.require_path = 'lib'