superdupe 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,7 @@ class Dupe
18
18
  # database.delete :book, proc {|b| b.id < 10} # --> would delete all books found who's id is less than 10
19
19
  # database.delete :books, proc {|b| b.id < 10} # --> would delete all books found who's id is less than 10
20
20
  def delete(resource_name, conditions=nil)
21
- model_name = resource_name.to_s.singularize.to_sym
21
+ model_name = resource_name.plural? ? resource_name.to_s.singularize.to_sym : resource_name.to_s.to_sym
22
22
  raise StandardError, "Invalid DELETE operation: The resource #{model_name} has not been defined" unless @tables[model_name]
23
23
 
24
24
  if conditions
@@ -360,7 +360,11 @@ class Dupe
360
360
  # Notice that by using the plural form of the model name, we ensure that we receive back an array -
361
361
  # even in the case that the query did not find any results (it simply returns an empty array).
362
362
  def find(model_name, &block) # yield: record
363
- results = database.select model_name.to_s.singularize.to_sym, block
363
+ if model_name.plural?
364
+ results = database.select model_name.to_s.singularize.to_sym, block
365
+ else
366
+ results = database.select model_name.to_s.to_sym, block
367
+ end
364
368
  model_name.plural? ? results : results.first
365
369
  end
366
370
 
@@ -475,7 +479,7 @@ class Dupe
475
479
  end
476
480
 
477
481
  def model_exists(model_name)
478
- models[model_name.to_s.singularize.to_sym]
482
+ model_name.plural? ? models[model_name.to_s.singularize.to_sym] : models[model_name.to_s.to_sym]
479
483
  end
480
484
 
481
485
  def create_model(model_name)
@@ -7,9 +7,9 @@ module Ns
7
7
  end
8
8
 
9
9
  describe Ns::Address do
10
-
11
10
  context "creating and saving a namespaced resource" do
12
11
  it 'should allow to first instantiate and then save a resource' do
12
+ Dupe.reset
13
13
  Dupe.define :"Ns::Address"
14
14
  Ns::Address.find(:all).size.should be(0)
15
15
  new_address = Ns::Address.new
@@ -19,4 +19,16 @@ describe Ns::Address do
19
19
  end
20
20
  end
21
21
 
22
+
23
+ context "create a mock of the address" do
24
+ before(:each) do
25
+ Dupe.reset
26
+ Dupe.create :"Ns::Address", :id => 100, :name => 'test'
27
+ end
28
+
29
+ it "should find address with id" do
30
+ Ns::Address.find(100).should_not be_blank
31
+ end
32
+ end
33
+
22
34
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superdupe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marco Ribi