orm_adapter 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +5 -1
- data/History.txt +9 -1
- data/lib/orm_adapter/adapters/active_record.rb +7 -5
- data/lib/orm_adapter/version.rb +1 -1
- data/orm_adapter.gemspec +2 -2
- data/spec/orm_adapter/adapters/active_record_spec.rb +21 -1
- data/spec/orm_adapter_spec.rb +1 -1
- metadata +3 -6
data/Gemfile.lock
CHANGED
@@ -29,6 +29,9 @@ GEM
|
|
29
29
|
dm-types (= 1.0.2)
|
30
30
|
dm-validations (= 1.0.2)
|
31
31
|
diff-lcs (1.1.2)
|
32
|
+
dm-active_model (1.0.2)
|
33
|
+
activemodel (~> 3.0.0)
|
34
|
+
dm-core (~> 1.0.2)
|
32
35
|
dm-aggregates (1.0.2)
|
33
36
|
dm-core (~> 1.0.2)
|
34
37
|
dm-constraints (1.0.2)
|
@@ -106,10 +109,11 @@ PLATFORMS
|
|
106
109
|
DEPENDENCIES
|
107
110
|
activerecord (~> 3.0.0)
|
108
111
|
datamapper
|
112
|
+
dm-active_model
|
109
113
|
dm-sqlite-adapter
|
110
114
|
jeweler
|
111
115
|
mongoid (~> 2.0.0.beta.17)
|
112
116
|
rake
|
113
|
-
rspec (~> 2.0.0.
|
117
|
+
rspec (~> 2.0.0.rc)
|
114
118
|
sqlite3-ruby
|
115
119
|
yard
|
data/History.txt
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
==
|
1
|
+
== 0.0.3
|
2
|
+
|
3
|
+
* ActiveRecord's OrmAdapter handles non standard foreign key names [Ian White]
|
4
|
+
* fix ruby 1.9.2 problems. [Ian White]
|
5
|
+
- removes "can't add a new key into hash during iteration" problem with ActiveRecord OrmAdapter
|
6
|
+
- removes problem with rspec 2 mocks interacting with ruby 1.9.2 #to_ary
|
7
|
+
|
8
|
+
|
9
|
+
== 0.0.2
|
2
10
|
|
3
11
|
* Add #get to the API. Ensure both #get and #get! complies with to_key requirements. [José Valim]
|
4
12
|
* Extract tests into shared example. Give instructions on how to write a new adapter. [Ian White]
|
@@ -64,14 +64,16 @@ class ActiveRecord::Base
|
|
64
64
|
|
65
65
|
# Introspects the klass to convert and objects in conditions into foreign key and type fields
|
66
66
|
def conditions_to_fields(conditions)
|
67
|
-
|
67
|
+
fields = {}
|
68
68
|
conditions.each do |key, value|
|
69
|
-
if value.is_a?(ActiveRecord::Base) && klass.
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
if value.is_a?(ActiveRecord::Base) && (assoc = klass.reflect_on_association(key.to_sym)) && assoc.belongs_to?
|
70
|
+
fields[assoc.primary_key_name] = value.send(value.class.primary_key)
|
71
|
+
fields[assoc.options[:foreign_type]] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
|
72
|
+
else
|
73
|
+
fields[key] = value
|
73
74
|
end
|
74
75
|
end
|
76
|
+
fields
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
data/lib/orm_adapter/version.rb
CHANGED
data/orm_adapter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{orm_adapter}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ian White", "Jose Valim"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-12}
|
13
13
|
s.description = %q{Provides a single point of entry for using basic features of ruby ORMs}
|
14
14
|
s.email = %q{ian.w.white@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,7 +42,7 @@ else
|
|
42
42
|
end
|
43
43
|
|
44
44
|
specify "#model_classes should return all of the non abstract model classes (that are not in except_classes)" do
|
45
|
-
subject.model_classes.should
|
45
|
+
subject.model_classes.should include(User, Note)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,6 +50,26 @@ else
|
|
50
50
|
let(:user_class) { User }
|
51
51
|
let(:note_class) { Note }
|
52
52
|
end
|
53
|
+
|
54
|
+
describe "#conditions_to_fields" do
|
55
|
+
describe "with non-standard association keys" do
|
56
|
+
class PerverseNote < Note
|
57
|
+
belongs_to :user, :foreign_key => 'owner_id'
|
58
|
+
belongs_to :pwner, :polymorphic => true, :foreign_key => 'owner_id', :foreign_type => 'owner_type'
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:user) { User.create! }
|
62
|
+
let(:adapter) { PerverseNote.to_adapter }
|
63
|
+
|
64
|
+
it "should convert polymorphic object in conditions to the appropriate fields" do
|
65
|
+
adapter.send(:conditions_to_fields, :pwner => user).should == {'owner_id' => user.id, 'owner_type' => user.class.name}
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should convert belongs_to object in conditions to the appropriate fields" do
|
69
|
+
adapter.send(:conditions_to_fields, :user => user).should == {'owner_id' => user.id}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
53
73
|
end
|
54
74
|
end
|
55
75
|
end
|
data/spec/orm_adapter_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orm_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Ian White
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-12 00:00:00 +01:00
|
20
19
|
default_executable:
|
21
20
|
dependencies: []
|
22
21
|
|
@@ -65,7 +64,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
64
|
requirements:
|
66
65
|
- - ">="
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
hash: 3
|
69
67
|
segments:
|
70
68
|
- 0
|
71
69
|
version: "0"
|
@@ -74,7 +72,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
72
|
requirements:
|
75
73
|
- - ">="
|
76
74
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 3
|
78
75
|
segments:
|
79
76
|
- 0
|
80
77
|
version: "0"
|