Permalink
Browse files

Changed UUID to BigDecimal

  • Loading branch information...
1 parent f0786ea commit 0c0665469b45596cae8b2a66d54819c77fb9870f @darthdeus committed Jan 27, 2012
Showing with 9 additions and 8 deletions.
  1. +2 −2 app.rb
  2. +3 −2 lib/dynamo_record.rb
  3. +4 −4 spec/dynamo_record_spec.rb
View
4 app.rb
@@ -30,14 +30,14 @@ class Task < DynamoRecord
task = Task.find_instance(params['id'])
task['name'] = params['name']
- task['tags'] = params['tags'].split(",")
+ task['tags'] = params['tags'].split(",").map(&:strip)
content_type :json
params.to_json
end
post '/create' do
- task = Task.create(:name => params['name'], :tags => params['tags'].split(","))
+ task = Task.create(:name => params['name'], :tags => params['tags'].split(",").map(&:strip))
content_type :json
hash = task.attributes.to_h
View
@@ -48,8 +48,9 @@ def find_instance(id)
def create(params)
self.establish_connection unless @connected
- # We need to chomp the UUID to fit in the ID column, there is probably a better way to do this
- uuid = UUIDTools::UUID.timestamp_create.to_s[0..10].to_i
+ # We need to convert the UUID to BigDecimal to fit in the ID column,
+ # there is probably a better way to do this
+ uuid = BigDecimal.new(UUIDTools::UUID.timestamp_create.to_s)
@table.items.create({:id => uuid}.merge(params))
end
end
@@ -18,29 +18,29 @@ class Task < DynamoRecord
table_name :tasks
end
- t = Task.new
+ t = Task.new(stub(:attributes => {}))
t.table_name.should == "tasks"
end
it "sets a default table name from the class" do
class Task < DynamoRecord; end
- t = Task.new
+ t = Task.new(stub(:attributes => {}))
t.table_name.should == "tasks"
end
it "allows to retrieve attributes via hash notation" do
class Task < DynamoRecord; end
- t = Task.new
+ t = Task.new(stub(:attributes => {}))
t["name"] = "foobar"
t["name"].should == "foobar"
end
it "allows to override table name per instance basis" do
class Task < DynamoRecord; end
- t = Task.new
+ t = Task.new(stub(:attributes => {}))
t.table_name.should == "tasks"
t.table_name = "bazinga"
t.table_name.should == "bazinga"

0 comments on commit 0c06654

Please sign in to comment.