Skip to content
Browse files

make source sync play nice with activerelation proxies

  • Loading branch information...
1 parent b47ae19 commit 1d42bf388a1d16a925876e30ed28a7d53fb1269d Matthew Kane Parker committed Sep 24, 2012
View
4 lib/license_finder/persistence/yaml/dependency.rb
@@ -89,6 +89,10 @@ def update_attributes new_values
save
end
+ def approved?
+ !!approved
+ end
+
def save
self.class.update(attributes)
end
View
8 lib/license_finder/source_syncer.rb
@@ -2,13 +2,14 @@ module LicenseFinder
class SourceSyncer
def initialize(source_dependencies, dependencies)
@source_dependencies = Array source_dependencies
- @dependencies = Array dependencies
+ @dependencies = dependencies
end
def sync!
destroy_obsolete_dependencies
update_existing_dependencies
create_new_dependencies
+ dependencies
end
protected
@@ -30,8 +31,9 @@ def update_existing_dependencies
end
def create_new_dependencies
- source_dependencies.each do |s|
- Dependency.new(s.attributes).save
+ source_dependencies.each do |d|
+ dependencies << d
+ d.save
end
end
end
View
13 spec/lib/license_finder/source_syncer_spec.rb
@@ -21,12 +21,17 @@ module LicenseFinder
it "creates any new source dependencies" do
source_dep = double :source_dep, name: "foo", attributes: double(:attributes)
- new_dep = double :new_dep
- Dependency.should_receive(:new).with(source_dep.attributes).and_return new_dep
- new_dep.should_receive(:save)
+
+ source_dep.should_receive :save
SourceSyncer.new([source_dep], []).sync!
end
+
+ it "returns the synced dependency set" do
+ source_dep = double(:source_dep, name: "source_dep", attributes: double(:attributes)).as_null_object
+ existing_dep = double :existing_dep, name: "existing", merge: nil
+
+ SourceSyncer.new([source_dep, existing_dep], [existing_dep]).sync!.should =~ [source_dep, existing_dep]
+ end
end
end
-
View
25 spec/support/shared_examples/persistence/dependency.rb
@@ -26,7 +26,11 @@
context "with known attributes" do
it "should set the all of the attributes on the instance" do
attributes.each do |key, value|
- subject.send("#{key}").should equal(value), "expected #{value.inspect} for #{key}, got #{subject.send("#{key}").inspect}"
+ if key != "approved"
+ subject.send("#{key}").should equal(value), "expected #{value.inspect} for #{key}, got #{subject.send("#{key}").inspect}"
+ else
+ subject.approved?.should == value
+ end
end
end
end
@@ -49,7 +53,7 @@
unapproved = klass.unapproved
unapproved.count.should == 1
- unapproved.collect(&:approved).any?.should be_false
+ unapproved.collect(&:approved?).any?.should be_false
end
end
@@ -91,13 +95,13 @@
saved_dep = klass.find_by_name(dep.name)
- saved_dep.attributes.should == dep.attributes
-
- dep.version = "new version"
- dep.save
-
- saved_dep = klass.find_by_name(dep.name)
- saved_dep.version.should == "new version"
+ attributes.each do |key, value|
+ if key != "approved"
+ saved_dep.send("#{key}").should eql(value), "expected #{value.inspect} for #{key}, got #{saved_dep.send("#{key}").inspect}"
+ else
+ saved_dep.approved?.should == value
+ end
+ end
end
end
@@ -108,7 +112,8 @@
gem.update_attributes(updated_attributes)
saved_gem = klass.find_by_name(gem.name)
- saved_gem.attributes.should == gem.attributes.merge(updated_attributes)
+ saved_gem.version.should == "new_version"
+ saved_gem.license.should == "updated_license"
end
end

0 comments on commit 1d42bf3

Please sign in to comment.
Something went wrong with that request. Please try again.