rspec_candy 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -2
- data/lib/rspec_candy/helpers.rb +1 -1
- data/lib/rspec_candy/helpers/rails/store_with_values.rb +34 -0
- data/lib/rspec_candy/version.rb +1 -1
- data/rspec_candy.gemspec +1 -0
- data/spec/rspec1/Gemfile +1 -2
- data/spec/rspec2/Gemfile +2 -1
- data/spec/shared/app_root/app/models/model.rb +2 -0
- data/spec/shared/app_root/db/migrate/001_create_model.rb +1 -0
- data/spec/shared/rspec_candy/helpers/rails/store_with_values_spec.rb +84 -0
- metadata +65 -32
- data/lib/rspec_candy/helpers/rails/create_without_callbacks.rb +0 -29
- data/spec/shared/rspec_candy/helpers/rails/create_without_callbacks_spec.rb +0 -51
data/README.md
CHANGED
@@ -154,7 +154,7 @@ If you only care about the matchers or helpers you can also more specifically re
|
|
154
154
|
|
155
155
|
### Extensions to **ActiveRecord::Base**
|
156
156
|
|
157
|
-
**
|
157
|
+
**store_with_values**
|
158
158
|
|
159
159
|
Only on Rails.
|
160
160
|
|
@@ -164,7 +164,8 @@ If you only care about the matchers or helpers you can also more specifically re
|
|
164
164
|
|
165
165
|
##Changes from previous versions:
|
166
166
|
|
167
|
-
- `new_and_store` has been renamed `
|
167
|
+
- `new_and_store` has been renamed to `store_with_values`
|
168
|
+
- `create_without_callbacks` has been renamed to `store_with_values`
|
168
169
|
- `keep_invalid!` has been renamed to `prevent_storage`
|
169
170
|
- `Object#should_not_receive_and_execute` has been removed (same as `Object#should_not_receive`)
|
170
171
|
- `should_receive_all_with` (over-generic method name for a helper that is rarely useful)
|
data/lib/rspec_candy/helpers.rb
CHANGED
@@ -9,7 +9,7 @@ require 'rspec_candy/helpers/stub_any_instance'
|
|
9
9
|
require 'rspec_candy/helpers/stub_existing'
|
10
10
|
|
11
11
|
if RSpecCandy::Switcher.rails_loaded?
|
12
|
-
require 'rspec_candy/helpers/rails/
|
12
|
+
require 'rspec_candy/helpers/rails/store_with_values'
|
13
13
|
require 'rspec_candy/helpers/rails/it_should_run_callbacks'
|
14
14
|
require 'rspec_candy/helpers/rails/prevent_storage'
|
15
15
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RSpecCandy
|
2
|
+
module Helpers
|
3
|
+
module Rails
|
4
|
+
module StoreWithValues
|
5
|
+
|
6
|
+
def store_with_values(values = {})
|
7
|
+
record = new
|
8
|
+
if Switcher.rails_version == :rails2
|
9
|
+
record.send(:attributes=, values, false)
|
10
|
+
record.send(:create_without_callbacks)
|
11
|
+
else
|
12
|
+
require 'sneaky-save'
|
13
|
+
record.assign_attributes(values, :without_protection => true)
|
14
|
+
record.sneaky_save
|
15
|
+
end
|
16
|
+
record
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_and_store(*args)
|
20
|
+
warn 'new_and_store is deprecated. Use store_with_values instead.'
|
21
|
+
store_with_values(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_without_callbacks(*args)
|
25
|
+
warn 'create_without_callbacks is deprecated because the name suggested that it honors mass-assignment protection. Use store_with_values instead.'
|
26
|
+
store_with_values(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveRecord::Base.send(:extend, self)
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/rspec_candy/version.rb
CHANGED
data/rspec_candy.gemspec
CHANGED
data/spec/rspec1/Gemfile
CHANGED
@@ -2,6 +2,7 @@ source :rubygems
|
|
2
2
|
|
3
3
|
gem 'sqlite3'
|
4
4
|
gem 'rails', '~>2'
|
5
|
+
gem 'has_defaults'
|
5
6
|
gem 'rspec', '~>1'
|
6
7
|
gem 'rspec-rails', '~>1'
|
7
8
|
gem 'ruby-debug', :platforms => :ruby_18
|
@@ -9,8 +10,6 @@ gem 'debugger', :platforms => :ruby_19
|
|
9
10
|
gem 'rspec_candy', :path => '../..'
|
10
11
|
gem 'test-unit', '~>1.2', :platforms => :ruby_19
|
11
12
|
|
12
|
-
|
13
13
|
group :state_machine do
|
14
14
|
gem 'state_machine'
|
15
15
|
end
|
16
|
-
|
data/spec/rspec2/Gemfile
CHANGED
@@ -2,6 +2,7 @@ source :rubygems
|
|
2
2
|
|
3
3
|
gem 'sqlite3'
|
4
4
|
gem 'rails', '~>3'
|
5
|
+
gem 'has_defaults'
|
5
6
|
gem 'rspec', '~>2'
|
6
7
|
gem 'rspec-rails', '~>2'
|
7
8
|
gem 'ruby-debug', :platforms => :ruby_18
|
@@ -10,4 +11,4 @@ gem 'rspec_candy', :path => '../..'
|
|
10
11
|
|
11
12
|
group :state_machine do
|
12
13
|
gem 'state_machine'
|
13
|
-
end
|
14
|
+
end
|
@@ -4,6 +4,8 @@ class Model < ActiveRecord::Base
|
|
4
4
|
after_save :after_save_callback1, :after_save_callback2
|
5
5
|
before_save :before_save_callback1, :before_save_callback2
|
6
6
|
|
7
|
+
belongs_to :associated_model, :class_name => 'Model'
|
8
|
+
|
7
9
|
if respond_to? :around_save
|
8
10
|
around_save :around_save_callback1, :around_save_callback2
|
9
11
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'has_defaults'
|
3
|
+
|
4
|
+
describe RSpecCandy::Helpers::Rails::StoreWithValues do
|
5
|
+
|
6
|
+
describe ActiveRecord::Base do
|
7
|
+
|
8
|
+
describe '.store_with_values' do
|
9
|
+
|
10
|
+
it 'should run after_initialize callbacks' do
|
11
|
+
model = Model.disposable_copy do
|
12
|
+
has_defaults :string_field => 'Hello Universe'
|
13
|
+
end
|
14
|
+
|
15
|
+
record = model.store_with_values
|
16
|
+
record.string_field.should == 'Hello Universe'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should allow setting associations' do
|
20
|
+
associated_model = Model.create!
|
21
|
+
|
22
|
+
record = Model.store_with_values(:associated_model => associated_model)
|
23
|
+
record.reload
|
24
|
+
record.associated_model.should == associated_model
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow setting primary keys' do
|
28
|
+
record = Model.store_with_values(:id => 1337)
|
29
|
+
record.id.should == 1337
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create a record without running callbacks or validations' do
|
33
|
+
model = Model.disposable_copy do
|
34
|
+
before_save :crash
|
35
|
+
validate :crash
|
36
|
+
def crash
|
37
|
+
raise 'callback was run'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
record = nil
|
41
|
+
expect do
|
42
|
+
record = model.store_with_values(:string_field => 'foo')
|
43
|
+
end.to_not raise_error
|
44
|
+
record.string_field.should == 'foo'
|
45
|
+
record.should be_a(Model)
|
46
|
+
record.id.should be_a(Fixnum)
|
47
|
+
record.should_not be_new_record
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should work with single table inheritance' do
|
51
|
+
child = StiChild.store_with_values(:string_field => 'foo')
|
52
|
+
child.string_field.should == 'foo'
|
53
|
+
child.should be_a(StiChild)
|
54
|
+
child.id.should be_a(Fixnum)
|
55
|
+
child.type.should == 'StiChild'
|
56
|
+
child.should_not be_new_record
|
57
|
+
StiChild.all.should == [child]
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.create_without_callbacks' do
|
63
|
+
|
64
|
+
it 'should print a deprecation warning urging to use .store_with_values instead' do
|
65
|
+
Model.should_receive(:warn).with(/Use store_with_values instead/i)
|
66
|
+
Model.should_receive(:store_with_values).with('args')
|
67
|
+
Model.create_without_callbacks('args')
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '.new_and_store' do
|
73
|
+
|
74
|
+
it 'should print a deprecation warning urging to use .store_with_values instead' do
|
75
|
+
Model.should_receive(:warn).with(/Use store_with_values instead/i)
|
76
|
+
Model.should_receive(:store_with_values).with('args')
|
77
|
+
Model.new_and_store('args')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
metadata
CHANGED
@@ -1,39 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_candy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 8
|
10
|
+
version: 0.2.8
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Henning Koch
|
9
14
|
- Tobias Kraze
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
|
19
|
+
date: 2013-02-22 00:00:00 +01:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
16
23
|
name: rspec
|
17
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
26
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
23
34
|
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sneaky-save
|
24
38
|
prerelease: false
|
25
|
-
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
26
40
|
none: false
|
27
|
-
requirements:
|
28
|
-
- -
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
31
50
|
description: RSpec helpers and matchers we use in our daily work at makandra.
|
32
51
|
email: henning.koch@makandra.de
|
33
52
|
executables: []
|
53
|
+
|
34
54
|
extensions: []
|
55
|
+
|
35
56
|
extra_rdoc_files: []
|
36
|
-
|
57
|
+
|
58
|
+
files:
|
37
59
|
- .gitignore
|
38
60
|
- .travis.yml
|
39
61
|
- README.md
|
@@ -45,9 +67,9 @@ files:
|
|
45
67
|
- lib/rspec_candy/helpers/disposable_copy.rb
|
46
68
|
- lib/rspec_candy/helpers/it_should_act_like.rb
|
47
69
|
- lib/rspec_candy/helpers/new_with_stubs.rb
|
48
|
-
- lib/rspec_candy/helpers/rails/create_without_callbacks.rb
|
49
70
|
- lib/rspec_candy/helpers/rails/it_should_run_callbacks.rb
|
50
71
|
- lib/rspec_candy/helpers/rails/prevent_storage.rb
|
72
|
+
- lib/rspec_candy/helpers/rails/store_with_values.rb
|
51
73
|
- lib/rspec_candy/helpers/should_receive_and_execute.rb
|
52
74
|
- lib/rspec_candy/helpers/should_receive_and_return.rb
|
53
75
|
- lib/rspec_candy/helpers/should_receive_chain.rb
|
@@ -106,9 +128,9 @@ files:
|
|
106
128
|
- spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
|
107
129
|
- spec/shared/rspec_candy/helpers/it_should_act_like_spec.rb
|
108
130
|
- spec/shared/rspec_candy/helpers/new_with_stubs_spec.rb
|
109
|
-
- spec/shared/rspec_candy/helpers/rails/create_without_callbacks_spec.rb
|
110
131
|
- spec/shared/rspec_candy/helpers/rails/it_should_run_callbacks_spec.rb
|
111
132
|
- spec/shared/rspec_candy/helpers/rails/prevent_storage_spec.rb
|
133
|
+
- spec/shared/rspec_candy/helpers/rails/store_with_values_spec.rb
|
112
134
|
- spec/shared/rspec_candy/helpers/should_receive_and_execute_spec.rb
|
113
135
|
- spec/shared/rspec_candy/helpers/should_receive_and_return_spec.rb
|
114
136
|
- spec/shared/rspec_candy/helpers/should_receive_chain_spec.rb
|
@@ -119,28 +141,39 @@ files:
|
|
119
141
|
- spec/shared/rspec_candy/matchers/include_hash_spec.rb
|
120
142
|
- spec/shared/support/matchers/pass_as_describe_block.rb
|
121
143
|
- spec/shared/support/matchers/pass_as_example.rb
|
144
|
+
has_rdoc: true
|
122
145
|
homepage: https://github.com/makandra/rspec_candy
|
123
146
|
licenses: []
|
147
|
+
|
124
148
|
post_install_message:
|
125
149
|
rdoc_options: []
|
126
|
-
|
150
|
+
|
151
|
+
require_paths:
|
127
152
|
- lib
|
128
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
154
|
none: false
|
130
|
-
requirements:
|
131
|
-
- -
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
|
134
|
-
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
163
|
none: false
|
136
|
-
requirements:
|
137
|
-
- -
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
hash: 3
|
168
|
+
segments:
|
169
|
+
- 0
|
170
|
+
version: "0"
|
140
171
|
requirements: []
|
172
|
+
|
141
173
|
rubyforge_project:
|
142
|
-
rubygems_version: 1.
|
174
|
+
rubygems_version: 1.3.9.5
|
143
175
|
signing_key:
|
144
176
|
specification_version: 3
|
145
177
|
summary: RSpec helpers and matchers we use in our daily work at makandra.
|
146
178
|
test_files: []
|
179
|
+
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module RSpecCandy
|
2
|
-
module Helpers
|
3
|
-
module Rails
|
4
|
-
module CreateWithoutCallbacks
|
5
|
-
|
6
|
-
def create_without_callbacks(*args)
|
7
|
-
table_name = self.table_name
|
8
|
-
plain_model = Class.new(ActiveRecord::Base) do
|
9
|
-
self.table_name = table_name
|
10
|
-
end
|
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!
|
16
|
-
find plain_record.id
|
17
|
-
end
|
18
|
-
|
19
|
-
def new_and_store(*args)
|
20
|
-
warn 'new_and_store is deprecated. Use create_without_callbacks instead.'
|
21
|
-
create_without_callbacks(*args)
|
22
|
-
end
|
23
|
-
|
24
|
-
ActiveRecord::Base.send(:extend, self)
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RSpecCandy::Helpers::Rails::CreateWithoutCallbacks do
|
4
|
-
|
5
|
-
describe ActiveRecord::Base do
|
6
|
-
|
7
|
-
describe '.create_without_callbacks' do
|
8
|
-
|
9
|
-
it 'should create a record without running callbacks or validations' do
|
10
|
-
model = Model.disposable_copy do
|
11
|
-
before_save :crash
|
12
|
-
validate :crash
|
13
|
-
def crash
|
14
|
-
raise 'callback was run'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
record = nil
|
18
|
-
expect do
|
19
|
-
record = model.create_without_callbacks(:string_field => 'foo')
|
20
|
-
end.to_not raise_error
|
21
|
-
record.string_field.should == 'foo'
|
22
|
-
record.should be_a(Model)
|
23
|
-
record.id.should be_a(Fixnum)
|
24
|
-
record.should_not be_new_record
|
25
|
-
end
|
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
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '.new_and_store' do
|
40
|
-
|
41
|
-
it 'should print a deprecation warning urging to use .create_without_callbacks instead' do
|
42
|
-
Model.should_receive(:warn).with(/Use create_without_callbacks instead/i)
|
43
|
-
Model.should_receive(:create_without_callbacks).with('args')
|
44
|
-
Model.new_and_store('args')
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|