diff options
| author | mo khan <mo@mokhan.ca> | 2013-07-20 18:37:59 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-07-20 18:37:59 -0600 |
| commit | 94b7b2363733a2616b5a9f686938aa8d01c722ca (patch) | |
| tree | 3fc5fe0a6ca4a49f33abe8082a588828518ca2c0 | |
| parent | 48132ac30c34dc6c455c9445b2632a7bb56f0eca (diff) | |
delete records
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | lib/humble/database_table.rb | 4 | ||||
| -rw-r--r-- | lib/humble/mapping_configuration.rb | 4 | ||||
| -rw-r--r-- | lib/humble/session.rb | 4 | ||||
| -rw-r--r-- | spec/integration/delete_spec.rb | 17 |
5 files changed, 30 insertions, 1 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index badc4eb..5894206 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - humble (0.0.1374366460) + humble (0.0.1374367070) sequel GEM diff --git a/lib/humble/database_table.rb b/lib/humble/database_table.rb index 4fcdd8e..5ec22ba 100644 --- a/lib/humble/database_table.rb +++ b/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) diff --git a/lib/humble/mapping_configuration.rb b/lib/humble/mapping_configuration.rb index a62d98c..d007e93 100644 --- a/lib/humble/mapping_configuration.rb +++ b/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 diff --git a/lib/humble/session.rb b/lib/humble/session.rb index be12157..d00470b 100644 --- a/lib/humble/session.rb +++ b/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 diff --git a/spec/integration/delete_spec.rb b/spec/integration/delete_spec.rb new file mode 100644 index 0000000..684f99f --- /dev/null +++ b/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 |
