m2m_fast_insert 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- m2m_fast_insert (0.0.2)
4
+ m2m_fast_insert (0.0.3)
5
5
  activerecord (>= 3.0.0, < 4.0.0)
6
6
  activesupport (>= 3.0.0, < 4.0.0)
7
7
  rails (~> 3.0.13)
@@ -3,10 +3,11 @@ module M2MFastInsert
3
3
  attr_reader :ids, :options, :id, :join_table, :join_column_name, :table_name
4
4
 
5
5
  def initialize(id, join_column_name, table_name, join_table, *args)
6
- @ids = args[0].collect(&:to_i)
7
6
  @options = args[1].present? ? args[1] : {}
7
+ @id = id.to_i
8
+ @ids = args[0].collect(&:to_i)
8
9
  @ids.uniq! if options[:unique]
9
- @id = id
10
+ raise ArgumentError, "Can't have nil ID, perhaps you didn't save the record first?" if id.nil?
10
11
  @join_table = join_table
11
12
  @join_column_name = join_column_name
12
13
  @table_name = table_name
@@ -26,7 +27,7 @@ module M2MFastInsert
26
27
  end
27
28
 
28
29
  def fast_insert
29
- ActiveRecord::Base.connection.execute sql
30
+ ActiveRecord::Base.connection.execute(sql) unless ids.empty?
30
31
  end
31
32
  end
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module M2MFastInsert
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -37,6 +37,20 @@ module M2MFastInsert
37
37
  end
38
38
  end
39
39
 
40
+ describe "basic init" do
41
+ let(:ids) { [1,2] }
42
+ it "raises error on an empty ID" do
43
+ expect {
44
+ Base.new(nil, join_column_name, table_name, join_table, ids)
45
+ }.to raise_error(ArgumentError)
46
+ end
47
+
48
+ it "doesn't execute with an empty id list" do
49
+ ActiveRecord::Base.connection.should_not_receive(:execute)
50
+ Base.new(id, join_column_name, table_name, join_table, []).fast_insert
51
+ end
52
+ end
53
+
40
54
  describe "basic init" do
41
55
  let(:ids) { [1,2,Base] }
42
56
  it "denies non-fixnum ids" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m2m_fast_insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: -1507217789133467603
163
+ hash: 3375167432438345074
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements:
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: -1507217789133467603
172
+ hash: 3375167432438345074
173
173
  requirements: []
174
174
  rubyforge_project: m2m_fast_insert
175
175
  rubygems_version: 1.8.24