Permalink
Browse files

Added Set#fixtures which declares #memory_fixtures and #database_fixt…

…ures simultaneously
  • Loading branch information...
1 parent 1887251 commit 24d55e50de0a96da916ea69370df9d56288a4a7f Nathan Sobo committed Nov 14, 2008
View
@@ -55,8 +55,8 @@ def clear_all_sets
Relations::Set.clear_all
end
- def load_all_fixtures
- Relations::Set.load_all_fixtures
+ def load_fixtures
+ Relations::Set.load_fixtures
end
attr_writer :test_mode
@@ -6,7 +6,7 @@ def clear_all
instances.each {|set| set.clear}
end
- def load_all_fixtures
+ def load_fixtures
instances.each do |set|
set.load_memory_fixtures
set.load_database_fixtures
@@ -166,6 +166,11 @@ def notify_tuple_update_subscribers(tuple, attribute, old_value, new_value)
tuple_update_subscription_node.call(tuple, attribute, old_value, new_value)
end
+ def fixtures(fixtures_hash)
+ memory_fixtures(fixtures_hash)
+ database_fixtures(fixtures_hash)
+ end
+
def memory_fixtures(fixtures_hash)
declared_memory_fixtures.merge!(fixtures_hash)
end
@@ -182,6 +187,28 @@ def declared_database_fixtures
@declared_database_fixtures ||= {}
end
+ def load_fixtures
+ load_memory_fixtures
+ load_database_fixtures
+ end
+
+ def load_memory_fixtures
+ disable_after_create
+ declared_memory_fixtures.each do |id, attributes|
+ attributes[:id] = id.to_s
+ insert(new_tuple(attributes))
+ end
+ enable_after_create
+ end
+
+ def load_database_fixtures
+ table = Unison.origin.table_for(self)
+ declared_database_fixtures.each do |id, attributes|
+ attributes[:id] = id.to_s
+ table << attributes
+ end
+ end
+
def after_create_enabled?
@after_create_enabled
end
@@ -206,23 +233,6 @@ def disable_after_merge
@after_merge_enabled = false
end
- def load_memory_fixtures
- disable_after_create
- declared_memory_fixtures.each do |id, attributes|
- attributes[:id] = id.to_s
- insert(new_tuple(attributes))
- end
- enable_after_create
- end
-
- def load_database_fixtures
- table = Unison.origin.table_for(self)
- declared_database_fixtures.each do |id, attributes|
- attributes[:id] = id.to_s
- table << attributes
- end
- end
-
protected
attr_reader :signals
@@ -89,42 +89,6 @@ def create(attributes)
delegate method, :to => :set
end
- def where(predicate)
- set.where(predicate)
- end
-
- def order_by(*order_by_attributes)
- set.order_by(*order_by_attributes)
- end
-
- def project(*attributes_or_set)
- set.project(*attributes_or_set)
- end
-
- def singleton
- set.singleton
- end
-
- def fetch
- set.fetch
- end
-
- def push
- set.push
- end
-
- def pull
- set.pull
- end
-
- def find(id_or_predicate)
- set.find(id_or_predicate)
- end
-
- def find_or_pull(id_or_predicate)
- set.find_or_pull(id_or_predicate)
- end
-
def relates_to_many(name, &definition)
relation_definitions_on_self.push(RelationDefinition.new(name, definition, caller, false))
attr_reader "#{name}_relation"
@@ -144,22 +108,6 @@ def #{name}
class_eval(method_definition, __FILE__, method_definition_line)
end
- def memory_fixtures(fixtures)
- set.memory_fixtures(fixtures)
- end
-
- def load_memory_fixtures
- set.load_memory_fixtures
- end
-
- def database_fixtures(fixtures)
- set.database_fixtures(fixtures)
- end
-
- def load_database_fixtures
- set.load_database_fixtures
- end
-
protected
def single_set_inheritance_subclass?
superclass != PrimitiveTuple && superclass != Topic
@@ -26,15 +26,15 @@ module Relations
end
end
- describe ".load_all_fixtures" do
+ describe ".load_fixtures" do
it "calls #load_memory_fixtures and #load_database_fixtures on every instance of Set" do
publicize Set, :instances
Set.instances.should_not be_empty
Set.instances.each do |instance|
mock.proxy(instance).load_memory_fixtures
mock.proxy(instance).load_database_fixtures
end
- Set.load_all_fixtures
+ Set.load_fixtures
end
end
@@ -538,6 +538,22 @@ module Relations
}
end
+ describe "#fixtures" do
+ it "delegates to both #memory_fixtures and #database_fixtures" do
+ mock.proxy(users_set).memory_fixtures(fixtures_hash_1)
+ mock.proxy(users_set).database_fixtures(fixtures_hash_1)
+ users_set.fixtures(fixtures_hash_1)
+ end
+ end
+
+ describe "#load_fixtures" do
+ it "delegates to both #load_memory_fixtures and #load_database_fixtures" do
+ mock.proxy(users_set).load_memory_fixtures
+ mock.proxy(users_set).load_database_fixtures
+ users_set.load_fixtures
+ end
+ end
+
describe "#memory_fixtures" do
it "#merges the given hash of fixtures with the existing #declared_memory_fixtures" do
users_set.declared_memory_fixtures.should == {}
@@ -556,7 +556,6 @@ module Tuples
end
end
-
describe ".memory_fixtures" do
it "delegates to #set" do
fixtures_hash = {
View
@@ -15,10 +15,10 @@ module Unison
end
end
- describe ".load_all_fixtures" do
- it "delegates to Relations::Set.load_all_fixtures" do
- mock.proxy(Relations::Set).load_all_fixtures
- Unison.load_all_fixtures
+ describe ".load_fixtures" do
+ it "delegates to Relations::Set.load_fixtures" do
+ mock.proxy(Relations::Set).load_fixtures
+ Unison.load_fixtures
end
end
View
1 todo
@@ -3,6 +3,7 @@ Backlog
has_one :through
join with a TupleClass should use its #set
project with a TupleClass should use its #set
+proxy missing methods from TupleClasses to their #set
Release from should blow up if the object is not a retainer
cleanup PrimitiveTuple#[] specs
Instantiating an AttributesProjection with an operand that is composite raises an exception because we rely on #tuple_class

0 comments on commit 24d55e5

Please sign in to comment.