Skip to content

Commit

Permalink
Unit test stuff; Added tags to sale entities
Browse files Browse the repository at this point in the history
  • Loading branch information
LichP committed Oct 26, 2010
1 parent 5dbcc71 commit 35d2c57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
29 changes: 23 additions & 6 deletions lib/porp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.compile_ns_string

# List all keys in the current namespace
def self.ns_keys
[redis.get(/^#{ns}/)].flatten
[redis.keys(/^#{ns}/)].flatten
end

# Deletes all keys in the current namespace. This is intended primarily
Expand Down Expand Up @@ -135,13 +135,14 @@ def sale_entities
class SaleEntity < OrpModel
property :description, :long_desc

# Create a new StockEntity record
# Create a new SaleEntity record
def self.create(description)
new_sale_entity = self.new(self.new_id)
new_sale_entity.description = description
new_sale_entity
end


# Associates the sale entity with the supplied stock identity
def add_stock_entity(stock_id)
if StockEntity.exists?(stock_id)
redis.sadd("#{Porp.ns}:saleentity:id:#{id}:stockentities", stock_id)
Expand All @@ -150,13 +151,29 @@ def add_stock_entity(stock_id)
end
end

# Disassociates the sale entity with the supplied stock identity
def rem_stock_entity(stock_id)
redis.srem("#{Porp.ns}:saleentity:id:#{id}:stockentities", stock_id)
end

def sale_entities
redis.smembers("#{Porp.ns}:saleentity:id:#{id}:stockentities)")
end
# Returns a list of all stock entity ids associated with the sale entity
def stock_entities
redis.smembers("#{Porp.ns}:saleentity:id:#{id}:stockentities")
end

# Adds a tag
def add_tag(new_tag)
new_tag.downcase! # Also need to strip whitespace
redis.sadd("#{Porp.ns}:saleentity:id:#{id}:tags", new_tag)
redis.sadd("#{Porp.ns}:saleentities:tags:#{new_tag}", id)
end

# Removes a tag
def remove_tag(dead_tag)
dead_tag.downcase! # Also need to strip whitespace
redis.srem("#{Porp.ns}:saleentity:id:#{id}:tags", dead_tag)
redis.srem("#{Porp.ns}:saleentities:tags:#{dead_tag}", id)
end
end
end

7 changes: 5 additions & 2 deletions test/stockentity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
end

setup do

Porp.purge_current_namespace!
end

test "new stock entity should match input data" do

desc = "Stock entity creation test"
new_stke = Porp::StockEntity.new(desc)
assert 1 == new_stke.id
assert desc == new_stke.description
end

0 comments on commit 35d2c57

Please sign in to comment.