public
Rubygem
Fork of sam/dm-more
Description: Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper
Homepage: http://datamapper.org
Clone URL: git://github.com/dysinger/dm-more.git
Search Repo:
tested find_all_by
mattetti (author)
Sun May 04 23:08:46 -0700 2008
commit  56ad70cb1565891650d36dde08c9796764920be2
tree    002c1fe386d15d161091a49ae474c54e38f28ecd
parent  e09d74fda61c8434676e95f4fac078f76e09f092
...
10
11
12
 
13
14
15
...
17
18
19
20
 
21
22
23
...
10
11
12
13
14
15
16
...
18
19
20
 
21
22
23
24
0
@@ -10,6 +10,7 @@ module DataMapper
0
         first(search_attributes) || create(search_attributes.merge(create_attributes))
0
       end
0
       
0
+ private
0
       def method_missing_with_find_by(method, *args, &block)
0
         if match = matches_dynamic_finder?(method)
0
           finder = determine_finder(match)
0
@@ -17,7 +18,7 @@ module DataMapper
0
 
0
           conditions = {}
0
           attribute_names.each {|key| conditions[key] = args.shift}
0
-
0
+
0
           send(finder, conditions)
0
         else
0
           method_missing_without_find_by(method, *args, &block)
...
46
47
48
49
 
50
51
52
53
54
 
 
 
 
 
 
 
 
 
 
 
 
55
56
57
...
46
47
48
 
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -46,12 +46,24 @@ begin
0
       end
0
     end
0
     
0
- it "should find_by_name" do
0
+ it "should use find_by and use the name attribute to find a record" do
0
       repository(:sqlite3) do
0
         green_smoothie = GreenSmoothie.create({:name => 'Banana'})
0
         green_smoothie.should == GreenSmoothie.find_by_name('Banana')
0
       end
0
     end
0
+
0
+ it "should use find_all_by to find records using an attribute" do
0
+ repository(:sqlite3) do
0
+ green_smoothie = GreenSmoothie.create({:name => 'Banana'})
0
+ green_smoothie2 = GreenSmoothie.create({:name => 'Banana'})
0
+ found_records = GreenSmoothie.find_all_by_name('Banana')
0
+ found_records.length.should == 2
0
+ found_records.each do |found_record|
0
+ [green_smoothie, green_smoothie2].include?(found_record).should be_true
0
+ end
0
+ end
0
+ end
0
 
0
   end
0
 

Comments

    No one has commented yet.