Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Category#==

  • Loading branch information...
commit 582550d15ca1004a9609b37785033ebf25df3fc8 1 parent cae5f02
Florian R. Hanke authored
4 server/lib/picky/categories.rb
View
@@ -7,6 +7,8 @@ class Categories
forward :each,
:first,
:map,
+ :map!,
+ :include?,
:to => :categories
each_forward :cache,
@@ -51,7 +53,7 @@ def reset_qualifier_mapper
#
def << category
reset_qualifier_mapper # TODO Have an add method on QualifierMapper?
- categories << category
+ categories << category unless categories.include? category # This is wrong, and needs to be handled in index.rb
category_hash[category.name] = category
end
6 server/lib/picky/categories_realtime.rb
View
@@ -9,7 +9,11 @@ class Categories
:clear_realtime,
:build_realtime_mapping,
:to => :categories
-
+
+ def update object, where = :unshift
+ replace object, where = :unshift
+ end
+
end
end
7 server/lib/picky/category.rb
View
@@ -167,6 +167,13 @@ def index_name
def identifier
:"#{@index.identifier}:#{name}"
end
+
+ # Uniquely identified by index name and name.
+ #
+ def == other
+ index_name == other.index_name &&
+ name == other.name
+ end
#
#
2  server/lib/picky/category_realtime.rb
View
@@ -32,7 +32,7 @@ def replace object, where = :unshift
#
# Note: Takes a hash as opposed to the add/replace method.
#
- def replace_from hash
+ def replace_from hash #, id = (hash[:id] || hash['id'] || raise(IdNotGivenException.new)).send(key_format)
return unless text = hash[from] || hash[from.to_s]
raise IdNotGivenException.new unless id = hash[:id] || hash['id']
3  server/lib/picky/index_realtime.rb
View
@@ -6,7 +6,8 @@ class Index
forward :remove, # aka "delete".
:add, # aka "insert".
- :replace, # aka "insert or update". Thus, not called update.
+ :replace, # aka "delete then insert".
+ :update,
:replace_from,
:clear_realtime,
:build_realtime_mapping,
15 server/spec/lib/category_spec.rb
View
@@ -22,6 +22,21 @@
category.instance_variable_get(:@symbols).should == nil
end
+
+ context '#==' do
+ it 'is identical on the same thing' do
+ category.should == category
+ end
+ it 'looks only at index name and category name' do
+ category.should == described_class.new(:some_category, index)
+ end
+ it 'looks only at index name and category name' do
+ category.should_not == described_class.new(:some_other_category, index)
+ end
+ it 'results in a correct #include?' do
+ [category].include?(described_class.new(:some_category, index)).should == true
+ end
+ end
end
context 'directories' do
Please sign in to comment.
Something went wrong with that request. Please try again.