spec/structure/static_spec.rb in structure-0.12.1 vs spec/structure/static_spec.rb in structure-0.12.2
- old
+ new
@@ -1,9 +1,15 @@
require 'spec_helper'
class Structure
describe "A static structure" do
+ def replace_fixture(new_path)
+ City.instance_variable_set(:@all, nil)
+ fixture = File.expand_path("../../fixtures/#{new_path}", __FILE__)
+ City.set_data_path(fixture)
+ end
+
it "is enumerable" do
City.should be_an Enumerable
end
describe ".all" do
@@ -27,17 +33,20 @@
City.set_data_path("foo")
City.send(:data_path).should eql "foo"
end
end
- context "when sourced data does not include ids" do
+ context "when sourcing data without ids" do
before(:all) do
- City.instance_variable_set(:@all, nil)
- fixture = File.expand_path("../../fixtures/cities_without_id.yml", __FILE__)
- City.set_data_path(fixture)
+ @old_path = City.instance_variable_get(:@data_path)
+ replace_fixture("cities_without_id.yml")
end
+ after(:all) do
+ replace_fixture(@old_path)
+ end
+
it "should auto-increment the ids of loaded records" do
City.map(&:id).should =~ [1, 2, 3]
end
describe ".increment_id" do
@@ -51,9 +60,26 @@
it "auto-increments" do
City.send(:increment_id)
City.send(:increment_id).should eql 2
end
+ end
+ end
+
+ context "when sourcing nested models" do
+ before(:all) do
+ @old_path = City.instance_variable_get(:@data_path)
+ replace_fixture("cities_with_neighborhoods.yml")
+ end
+
+ after(:all) do
+ replace_fixture(@old_path)
+ end
+
+ it "loads nested models" do
+ pending
+ neighborhoods = City.first.neighborhoods
+ neighborhoods.first.should be_a Neighborhood
end
end
end
end