m4dbi 0.7.2 → 0.7.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.
@@ -67,7 +67,3 @@ module M4DBI
67
67
  end
68
68
  end
69
69
  end
70
-
71
-
72
-
73
-
data/lib/m4dbi/model.rb CHANGED
@@ -118,10 +118,12 @@ module M4DBI
118
118
  rec = nil
119
119
 
120
120
  dbh.transaction do |dbh_|
121
- num_inserted = dbh_.execute(
122
- "INSERT INTO #{table} ( #{cols} ) VALUES ( #{value_placeholders} )",
123
- *values
124
- ).affected_count
121
+ if keys.empty? && defined?( RDBI::Driver::PostgreSQL ) && RDBI::Driver::PostgreSQL === dbh.driver
122
+ sql = "INSERT INTO #{table} DEFAULT VALUES"
123
+ else
124
+ sql = "INSERT INTO #{table} ( #{cols} ) VALUES ( #{value_placeholders} )"
125
+ end
126
+ num_inserted = dbh_.execute( sql, *values ).affected_count
125
127
  if num_inserted > 0
126
128
  pk_hash = hash.slice( *(
127
129
  self.pk.map { |pk_col| pk_col.to_sym }
@@ -0,0 +1,3 @@
1
+ module M4DBI
2
+ VERSION = '0.7.3'
3
+ end
data/lib/m4dbi.rb CHANGED
@@ -3,10 +3,9 @@ require 'rdbi'
3
3
  require 'metaid'
4
4
  require 'thread'
5
5
 
6
- M4DBI_VERSION = '0.7.0'
7
-
8
6
  __DIR__ = File.expand_path( File.dirname( __FILE__ ) )
9
7
 
8
+ require "#{__DIR__}/m4dbi/version"
10
9
  require "#{__DIR__}/m4dbi/error"
11
10
  require "#{__DIR__}/m4dbi/traits"
12
11
  require "#{__DIR__}/m4dbi/hash"
data/spec/helper.rb CHANGED
@@ -12,7 +12,7 @@ $LOAD_PATH.unshift(
12
12
 
13
13
  require 'm4dbi'
14
14
 
15
- puts "M4DBI version: #{M4DBI_VERSION}"
15
+ puts "M4DBI version: #{M4DBI::VERSION}"
16
16
 
17
17
  # See test-schema*.sql and test-data.sql
18
18
  def connect_to_spec_database( database = ( ENV[ 'M4DBI_DATABASE' ] || 'm4dbi' ) )
data/spec/model.rb CHANGED
@@ -377,7 +377,7 @@ describe 'A M4DBI::Model subclass' do
377
377
  n.should.equal 3
378
378
  end
379
379
 
380
- it 'provides a means to create new records via #create( Hash )' do
380
+ it 'provides a means to create a new record from a Hash' do
381
381
  num_authors = @m_author.count
382
382
 
383
383
  a = @m_author.create(
@@ -427,7 +427,7 @@ describe 'A M4DBI::Model subclass' do
427
427
  reset_data
428
428
  end
429
429
 
430
- it 'provides a means to create new records via #create { |r| }' do
430
+ it 'provides a means to create a new record from a block' do
431
431
  should.raise( NoMethodError ) do
432
432
  @m_author.create { |rec|
433
433
  rec.no_such_column = 'foobar'
@@ -466,6 +466,20 @@ describe 'A M4DBI::Model subclass' do
466
466
  reset_data
467
467
  end
468
468
 
469
+ it 'provides a means to create a new record from an empty Hash' do
470
+ @m = Class.new( M4DBI::Model( :has_all_defaults ) )
471
+ num_records = @m.count
472
+
473
+ r = @m.create
474
+ @m.count.should.equal num_records + 1
475
+ r.should.not.be.nil
476
+ r.class.should.equal @m
477
+ r[ 'id' ].should.not.be.nil
478
+ r.should.respond_to :time_created
479
+ r.should.not.respond_to :no_column_by_this_name
480
+ r.time_created.should.not.be.nil
481
+ end
482
+
469
483
  it 'returns a record via #find_or_create( Hash )' do
470
484
  n = @m_author.count
471
485
  a = @m_author.find_or_create(
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: m4dbi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.2
5
+ version: 0.7.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pistos
@@ -50,6 +50,7 @@ files:
50
50
  - LICENCE
51
51
  - lib/m4dbi/database.rb
52
52
  - lib/m4dbi/model.rb
53
+ - lib/m4dbi/version.rb
53
54
  - lib/m4dbi/traits.rb
54
55
  - lib/m4dbi/collection.rb
55
56
  - lib/m4dbi/hash.rb