rspec_candy 0.2.5 → 0.2.6

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.
@@ -8,7 +8,11 @@ module RSpecCandy
8
8
  plain_model = Class.new(ActiveRecord::Base) do
9
9
  self.table_name = table_name
10
10
  end
11
- plain_record = plain_model.create!(*args)
11
+ plain_record = plain_model.new(*args)
12
+ if plain_record.respond_to?(:type=)
13
+ plain_record.type = name
14
+ end
15
+ plain_record.save!
12
16
  find plain_record.id
13
17
  end
14
18
 
@@ -1,3 +1,3 @@
1
1
  module RSpecCandy
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
@@ -0,0 +1,3 @@
1
+ class StiChild < StiParent
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class StiParent < ActiveRecord::Base
2
+
3
+ self.table_name = 'sti_models'
4
+
5
+ before_save :crash
6
+ validate :crash
7
+
8
+ def crash
9
+ raise 'callback was run'
10
+ end
11
+
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateStiModel < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :sti_models do |t|
5
+ t.string :type
6
+ t.string :string_field
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :sti_models
12
+ end
13
+
14
+ end
@@ -24,6 +24,16 @@ describe RSpecCandy::Helpers::Rails::CreateWithoutCallbacks do
24
24
  record.should_not be_new_record
25
25
  end
26
26
 
27
+ it 'should work with single table inheritance' do
28
+ child = StiChild.create_without_callbacks(:string_field => 'foo')
29
+ child.string_field.should == 'foo'
30
+ child.should be_a(StiChild)
31
+ child.id.should be_a(Fixnum)
32
+ child.type.should == 'StiChild'
33
+ child.should_not be_new_record
34
+ StiChild.all.should == [child]
35
+ end
36
+
27
37
  end
28
38
 
29
39
  describe '.new_and_store' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_candy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henning Koch
@@ -105,9 +105,12 @@ files:
105
105
  - spec/shared/app_root/app/controllers/application_controller.rb
106
106
  - spec/shared/app_root/app/models/model.rb
107
107
  - spec/shared/app_root/app/models/state_machine_model.rb
108
+ - spec/shared/app_root/app/models/sti_child.rb
109
+ - spec/shared/app_root/app/models/sti_parent.rb
108
110
  - spec/shared/app_root/config/initializers/state_machine.rb
109
111
  - spec/shared/app_root/db/migrate/001_create_model.rb
110
112
  - spec/shared/app_root/db/migrate/002_create_state_machine_model.rb
113
+ - spec/shared/app_root/db/migrate/003_create_sti_model.rb
111
114
  - spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
112
115
  - spec/shared/rspec_candy/helpers/it_should_act_like_spec.rb
113
116
  - spec/shared/rspec_candy/helpers/new_with_stubs_spec.rb