baza 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/baza.gemspec +1 -1
- data/include/drivers/mysql/mysql_columns.rb +1 -1
- data/include/drivers/sqlite3/sqlite3_columns.rb +1 -1
- data/include/model_handler.rb +1 -1
- data/spec/model_handler_spec.rb +20 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/baza.gemspec
CHANGED
@@ -6,7 +6,7 @@ class Baza::Driver::Mysql::Columns
|
|
6
6
|
end
|
7
7
|
|
8
8
|
#Returns the SQL for this column.
|
9
|
-
DATA_SQL_ALLOWED_KEYS = [:type, :maxlength, :name, :primarykey, :autoincr, :default, :comment, :after, :first, :storage, :null]
|
9
|
+
DATA_SQL_ALLOWED_KEYS = [:type, :maxlength, :name, :primarykey, :autoincr, :default, :comment, :after, :first, :storage, :null, :renames]
|
10
10
|
def data_sql(data)
|
11
11
|
data.each do |key, val|
|
12
12
|
raise "Invalid key: '#{key}' (#{key.class.name})." if !DATA_SQL_ALLOWED_KEYS.include?(key)
|
@@ -7,7 +7,7 @@ class Baza::Driver::Sqlite3::Columns
|
|
7
7
|
@args = args
|
8
8
|
end
|
9
9
|
|
10
|
-
DATA_SQL_ALLOWED_KEYS = [:name, :type, :maxlength, :autoincr, :primarykey, :null, :default, :default_func, :renames, :after]
|
10
|
+
DATA_SQL_ALLOWED_KEYS = [:name, :type, :maxlength, :autoincr, :primarykey, :null, :default, :default_func, :renames, :after, :renames]
|
11
11
|
#Returns SQL for a knjdb-compatible hash.
|
12
12
|
def data_sql(data)
|
13
13
|
data.each do |key, val|
|
data/include/model_handler.rb
CHANGED
@@ -408,7 +408,7 @@ class Baza::ModelHandler
|
|
408
408
|
|
409
409
|
#Searches for an object with the given data. If not found it creates it. Returns the found or created object in the end.
|
410
410
|
def get_or_add(classname, data, args = nil)
|
411
|
-
obj = self.get_by(classname, data)
|
411
|
+
obj = self.get_by(classname, data.clone)
|
412
412
|
obj = self.add(classname, data) if !obj
|
413
413
|
return obj
|
414
414
|
end
|
data/spec/model_handler_spec.rb
CHANGED
@@ -387,6 +387,26 @@ describe "Objects" do
|
|
387
387
|
$ob.delete_ids(:class => :Person, :ids => ids)
|
388
388
|
end
|
389
389
|
|
390
|
+
it "get_or_add" do
|
391
|
+
person1 = $ob.add(:Person, {
|
392
|
+
:name => "get_or_add"
|
393
|
+
})
|
394
|
+
|
395
|
+
person2 = $ob.get_or_add(:Person, {
|
396
|
+
:name => "get_or_add"
|
397
|
+
})
|
398
|
+
|
399
|
+
person2.id.should eql(person1.id)
|
400
|
+
person2[:name].should eql("get_or_add")
|
401
|
+
|
402
|
+
person3 = $ob.get_or_add(:Person, {
|
403
|
+
:name => "get_or_add3"
|
404
|
+
})
|
405
|
+
|
406
|
+
raise "Failure ID was the same" if person3.id == person2.id
|
407
|
+
person3[:name].should eql("get_or_add3")
|
408
|
+
end
|
409
|
+
|
390
410
|
it "should delete the temp database again." do
|
391
411
|
db_path = "#{Knj::Os.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
|
392
412
|
File.unlink(db_path) if File.exists?(db_path)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: baza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -250,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
250
250
|
- !ruby/object:Gem::Version
|
251
251
|
segments:
|
252
252
|
- 0
|
253
|
-
hash:
|
253
|
+
hash: 2079390994227772700
|
254
254
|
version: '0'
|
255
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
256
|
none: false
|