Commit 94b7b23
Changed files (5)
lib
spec
integration
lib/humble/database_table.rb
@@ -26,6 +26,10 @@ module Humble
end
end
+ def destroy(connection, entity)
+ connection[@name].where(:id => entity.id).delete
+ end
+
private
def has_default_value?(item)
lib/humble/mapping_configuration.rb
@@ -13,6 +13,10 @@ module Humble
@table.persist(connection, entity)
end
+ def delete_using(connection, entity)
+ @table.destroy(connection, entity)
+ end
+
def matches?(item)
self[:type] == item || item.is_a?(self[:type])
end
lib/humble/session.rb
@@ -19,6 +19,10 @@ module Humble
mapping_for(clazz).find_all_using(create_connection)
end
+ def delete(entity)
+ mapping_for(entity).delete_using(create_connection, entity)
+ end
+
private
attr_reader :connection_factory, :mapper_registry
spec/integration/delete_spec.rb
@@ -0,0 +1,17 @@
+require "integration_helper"
+
+describe "deletion" do
+ include_context "orm"
+
+ context "when deleting a record" do
+ before :each do
+ connection[:movies].insert(:name => 'mo money')
+ movie = session.find_all(Movie).first
+ session.delete(movie)
+ end
+
+ it "should remove it from the database" do
+ connection[:movies].all.count.should == 0
+ end
+ end
+end
Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- humble (0.0.1374366460)
+ humble (0.0.1374367070)
sequel
GEM