forked from hanabokuro/activerecord-turntable
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from drecom/feature/fix-fixtures-extensions
Fix Fixtures patch and add specs
- Loading branch information
Showing
4 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
spec/active_record/turntable/active_record_ext/fixture_set_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
require 'active_record' | ||
require 'active_record/turntable/active_record_ext/fixtures' | ||
|
||
describe ActiveRecord::FixtureSet do | ||
before(:all) do | ||
reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml")) | ||
end | ||
|
||
before do | ||
establish_connection_to(:test) | ||
truncate_shard | ||
end | ||
|
||
let(:fixtures_root) { File.join(File.dirname(__FILE__), "../../../fixtures") } | ||
let(:fixture_file) { File.join(fixtures_root, "cards.yml") } | ||
let(:cards) { YAML.load(ERB.new(IO.read(fixture_file)).result) } | ||
|
||
describe ".create_fixtures" do | ||
subject { ActiveRecord::FixtureSet.create_fixtures(fixtures_root, "cards") } | ||
it { is_expected.to be_instance_of(Array) } | ||
it "creates card records" do | ||
expect {subject}.to change {Card.count}.from(0).to(cards.size) | ||
end | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
require 'active_record' | ||
require 'active_record/turntable/active_record_ext/fixtures' | ||
|
||
describe ActiveRecord::TestFixtures do | ||
before(:all) do | ||
reload_turntable!(File.join(File.dirname(__FILE__), "../../../config/turntable.yml")) | ||
end | ||
|
||
before do | ||
establish_connection_to(:test) | ||
truncate_shard | ||
end | ||
|
||
let(:fixtures_root) { File.join(File.dirname(__FILE__), "../../../fixtures") } | ||
let(:fixture_file) { File.join(fixtures_root, "cards.yml") } | ||
let(:test_fixture_class) { Class.new(ActiveSupport::TestCase) { include ActiveRecord::TestFixtures } } | ||
let(:test_fixture) { test_fixture_class.new("test") } | ||
let(:cards) { YAML.load(ERB.new(IO.read(fixture_file)).result) } | ||
|
||
before do | ||
test_fixture_class.fixture_path = fixtures_root | ||
end | ||
|
||
describe "#setup_fixtures" do | ||
after do | ||
test_fixture.teardown_fixtures | ||
end | ||
|
||
subject { test_fixture.setup_fixtures } | ||
it { expect { subject }.not_to raise_error } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
card_1: | ||
id: 1 | ||
name: card_1 | ||
hp: 10 | ||
mp: 10 | ||
|
||
card_2: | ||
id: 2 | ||
name: card_2 | ||
hp: 20 | ||
mp: 20 |