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

Support the Rails 6.0.0 and RSpec 3 #137

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'http://rubygems.org'
gem 'rails', ">= 3.1", "< 5.1"
gem 'rails', ">= 3.1", "< 6.1"
gemspec
4 changes: 2 additions & 2 deletions seed-fu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ 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'
s.add_development_dependency "sqlite3"

s.files = Dir.glob("{lib}/**/*") + %w(LICENSE README.md CHANGELOG.md)
s.require_path = 'lib'
Expand Down
12 changes: 6 additions & 6 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 20 additions & 20 deletions spec/seeder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -50,23 +50,23 @@
s.first_name = "Bob"
end

SeededModel.count.should == 1
expect(SeededModel.count).to eq(1)

SeededModel.seed(:title, :login) do |s|
s.login = "frank"
s.title = "Peon"
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -40,6 +40,6 @@
end
load @file_name

SeededModel.find(1).title.should == "Dr"
expect(SeededModel.find(1).title).to eq("Dr")
end
end