rhodes-framework 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rhodes.rb +2 -2
- data/lib/rhom/rhom_db_adapter.rb +13 -3
- data/lib/rhom/rhom_object_factory.rb +3 -3
- data/lib/version.rb +2 -2
- data/spec/rhom_object_factory_spec.rb +22 -0
- metadata +3 -3
data/lib/rhodes.rb
CHANGED
data/lib/rhom/rhom_db_adapter.rb
CHANGED
@@ -91,11 +91,21 @@ module Rhom
|
|
91
91
|
def string_from_key_vals(values, delim)
|
92
92
|
vals = ""
|
93
93
|
values.each do |key,value|
|
94
|
-
|
95
|
-
vals << " #{key} = #{val}#{delim}"
|
94
|
+
vals << " #{key} = #{get_value_for_sql_stmt(value)}#{delim}"
|
96
95
|
end
|
97
96
|
vals
|
98
97
|
end
|
98
|
+
|
99
|
+
# generates a value for sql statement
|
100
|
+
def get_value_for_sql_stmt(value)
|
101
|
+
if value.is_a?(String)
|
102
|
+
"'#{value}'"
|
103
|
+
elsif value.nil?
|
104
|
+
"NULL"
|
105
|
+
else
|
106
|
+
"#{value}"
|
107
|
+
end
|
108
|
+
end
|
99
109
|
|
100
110
|
# support for select statements
|
101
111
|
# this function takes table name, columns (as a comma-separated list),
|
@@ -134,7 +144,7 @@ module Rhom
|
|
134
144
|
vals = ""
|
135
145
|
if table and values
|
136
146
|
values.each do |key,val|
|
137
|
-
value = val
|
147
|
+
value = get_value_for_sql_stmt(val)+","
|
138
148
|
cols << "#{key},"
|
139
149
|
vals << value
|
140
150
|
end
|
@@ -235,7 +235,7 @@ module Rhom
|
|
235
235
|
# Don't save objects with braces to database
|
236
236
|
val = self.inst_strip_braces(self.send(method.to_sym))
|
237
237
|
# add rows excluding object, source_id and update_type
|
238
|
-
unless self.method_name_reserved?(method)
|
238
|
+
unless self.method_name_reserved?(method)
|
239
239
|
fields = {"source_id"=>self.get_inst_source_id,
|
240
240
|
"object"=>obj,
|
241
241
|
"attrib"=>method,
|
@@ -263,8 +263,8 @@ module Rhom
|
|
263
263
|
|
264
264
|
# if the object's value doesn't match the database record
|
265
265
|
# then we procede with update
|
266
|
-
if
|
267
|
-
unless self.method_name_reserved?(attrib)
|
266
|
+
if old_val != new_val
|
267
|
+
unless self.method_name_reserved?(attrib)
|
268
268
|
::Rhom::RhomDbAdapter::delete_from_table(::Rhom::TABLE_NAME,
|
269
269
|
{"source_id"=>self.get_inst_source_id,
|
270
270
|
"object"=>obj,
|
data/lib/version.rb
CHANGED
@@ -171,6 +171,28 @@ describe "RhomObjectFactory" do
|
|
171
171
|
@new_acct.industry.should == "Technology"
|
172
172
|
end
|
173
173
|
|
174
|
+
it "should update an attribute to nil" do
|
175
|
+
new_attributes = {"name"=>nil}
|
176
|
+
@account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
|
177
|
+
@account.update_attributes(new_attributes)
|
178
|
+
|
179
|
+
@new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
|
180
|
+
|
181
|
+
@new_acct.name.should be_nil
|
182
|
+
@new_acct.industry.should == "Technology"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should update an attribute to empty string" do
|
186
|
+
new_attributes = {"name"=>""}
|
187
|
+
@account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
|
188
|
+
@account.update_attributes(new_attributes)
|
189
|
+
|
190
|
+
@new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
|
191
|
+
|
192
|
+
@new_acct.name.should == ""
|
193
|
+
@new_acct.industry.should == "Technology"
|
194
|
+
end
|
195
|
+
|
174
196
|
it "should store only last updated value for attrib" do
|
175
197
|
new_attributes1 = {"new_name"=>"Mobio Europe"}
|
176
198
|
@account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhodes-framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rhomobile Dev
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-31 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -197,6 +197,6 @@ rubyforge_project: rhodes-framework
|
|
197
197
|
rubygems_version: 1.3.1
|
198
198
|
signing_key:
|
199
199
|
specification_version: 2
|
200
|
-
summary: rhodes-framework 1.0.
|
200
|
+
summary: rhodes-framework 1.0.1
|
201
201
|
test_files: []
|
202
202
|
|