couchmodel 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -9,8 +9,8 @@ task :default => :spec
|
|
9
9
|
|
10
10
|
specification = Gem::Specification.new do |specification|
|
11
11
|
specification.name = "couchmodel"
|
12
|
-
specification.version = "0.1.
|
13
|
-
specification.date = "2010-07-
|
12
|
+
specification.version = "0.1.4"
|
13
|
+
specification.date = "2010-07-12"
|
14
14
|
|
15
15
|
specification.authors = [ "Philipp Bruell" ]
|
16
16
|
specification.email = "b.phifty@gmail.com"
|
@@ -62,6 +62,15 @@ module CouchModel
|
|
62
62
|
true
|
63
63
|
end
|
64
64
|
|
65
|
+
def update_attribute(name, value)
|
66
|
+
update_attributes name => value
|
67
|
+
end
|
68
|
+
|
69
|
+
def update_attributes(attributes)
|
70
|
+
self.attributes = attributes
|
71
|
+
self.save
|
72
|
+
end
|
73
|
+
|
65
74
|
private
|
66
75
|
|
67
76
|
def discard_changes!
|
@@ -104,7 +113,7 @@ module CouchModel
|
|
104
113
|
define_method :"#{key}=" do |value|
|
105
114
|
send :"#{key}_will_change!"
|
106
115
|
send :"#{key}_without_dirty=", value
|
107
|
-
end
|
116
|
+
end
|
108
117
|
end
|
109
118
|
|
110
119
|
end
|
@@ -66,25 +66,27 @@ module CouchModel
|
|
66
66
|
|
67
67
|
def define_date_reader(name)
|
68
68
|
define_method :"#{name}" do
|
69
|
-
|
69
|
+
value = @attributes[name.to_s]
|
70
|
+
value ? Date.parse(value) : nil
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
74
|
def define_date_writer(name)
|
74
75
|
define_method :"#{name}=" do |value|
|
75
|
-
@attributes[name.to_s] = value.to_s
|
76
|
+
@attributes[name.to_s] = value ? value.to_s : nil
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
80
|
def define_time_reader(name)
|
80
81
|
define_method :"#{name}" do
|
81
|
-
|
82
|
+
value = @attributes[name.to_s]
|
83
|
+
value ? Time.parse(value) : nil
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
87
|
def define_time_writer(name)
|
86
88
|
define_method :"#{name}=" do |value|
|
87
|
-
@attributes[name.to_s] = value.strftime("%Y-%m-%d %H:%M:%S %z")
|
89
|
+
@attributes[name.to_s] = value ? value.strftime("%Y-%m-%d %H:%M:%S %z") : nil
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
data/spec/integration/models.rb
CHANGED
@@ -36,7 +36,7 @@ end
|
|
36
36
|
|
37
37
|
def create_users_and_memberships
|
38
38
|
@user_one = User.create :username => "user one", :birthday => Date.parse("2000-07-07")
|
39
|
-
@user_two = User.create :username => "user two", :birthday =>
|
39
|
+
@user_two = User.create :username => "user two", :birthday => nil
|
40
40
|
@membership_one = Membership.create :created_at => Time.parse("2010-07-07"), :user => @user_one
|
41
41
|
@membership_two = Membership.create :created_at => Time.parse("2010-07-07"), :user => @user_two
|
42
42
|
end
|
@@ -124,7 +124,7 @@ describe ActiveTestModel do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
describe "save" do
|
129
129
|
|
130
130
|
before :each do
|
@@ -201,6 +201,33 @@ describe ActiveTestModel do
|
|
201
201
|
|
202
202
|
end
|
203
203
|
|
204
|
+
describe "update_attribute" do
|
205
|
+
|
206
|
+
it "should call update_attributes" do
|
207
|
+
@model.should_receive(:update_attributes).with(:name => "test")
|
208
|
+
@model.update_attribute :name, "test"
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "update_attributes" do
|
214
|
+
|
215
|
+
before :each do
|
216
|
+
@attributes = { :name => "test" }
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should set the attributes" do
|
220
|
+
@model.should_receive(:attributes=).with(@attributes)
|
221
|
+
@model.update_attributes @attributes
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should save the model" do
|
225
|
+
@model.should_receive(:save)
|
226
|
+
@model.update_attributes @attributes
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
204
231
|
describe "create!" do
|
205
232
|
|
206
233
|
it "should create a model" do
|
@@ -227,7 +254,7 @@ describe ActiveTestModel do
|
|
227
254
|
@model.should_receive(:destroy_callback)
|
228
255
|
do_destroy
|
229
256
|
end
|
230
|
-
|
257
|
+
|
231
258
|
end
|
232
259
|
|
233
260
|
describe "to_json" do
|
@@ -252,7 +279,7 @@ describe ActiveTestModel do
|
|
252
279
|
@model.name = "test"
|
253
280
|
@model.email = "test"
|
254
281
|
end
|
255
|
-
|
282
|
+
|
256
283
|
it "should return all attributes as xml" do
|
257
284
|
xml = @model.to_xml
|
258
285
|
xml.should =~ /^<\?xml version=.+1\.0.+ encoding=.+UTF-8.+\?>/
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Philipp Bruell
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-12 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|