prefactory 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/lib/prefactory/prefactory_lookup.rb +1 -0
- data/lib/prefactory/version.rb +1 -1
- data/lib/rspec/core/prefactory.rb +20 -5
- data/spec/database_setup.rb +4 -3
- data/spec/prefactory_spec.rb +10 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95b877ff898937be95f990b77ae54bdf56cdfc98
|
4
|
+
data.tar.gz: 62fe2f5a16f43f6c24e7163a26ec5d7644eff8fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3332c9909eeeb534459fbfc2c160e92c9d16b6fb011dccfedaf020f584debc47e03340d613b325c305b3fdd8c910e63064954fef22fe87877ca90c80aca600b2
|
7
|
+
data.tar.gz: 6a4a33926f48246b5a3bb25756b3cc7e64ad2b90e244bc8d23322110e83de4a5ec671e655eedea5f8168900125c4dd7acf86596c7037c3ef017c4ade048cdde2
|
data/.travis.yml
CHANGED
@@ -2,10 +2,10 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
-
- 2.
|
5
|
+
- 2.2.3
|
6
6
|
env:
|
7
7
|
- ACTIVE_RECORD_VERSION=4.0.0 RSPEC_VERSION=2.99
|
8
8
|
- ACTIVE_RECORD_VERSION=4.0.0
|
9
9
|
- ACTIVE_RECORD_VERSION=4.1.0 RSPEC_VERSION=2.99
|
10
10
|
- ACTIVE_RECORD_VERSION=4.1.0
|
11
|
-
- ACTIVE_RECORD_VERSION=4.2.0
|
11
|
+
- ACTIVE_RECORD_VERSION=4.2.0
|
data/lib/prefactory/version.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'prefactory/active_record_integration'
|
24
24
|
require 'rspec_around_all'
|
25
25
|
require 'prefactory/prefactory_lookup'
|
26
|
+
require 'yaml'
|
26
27
|
|
27
28
|
module Prefactory
|
28
29
|
class NotDefined
|
@@ -38,7 +39,11 @@ module Prefactory
|
|
38
39
|
@prefactory_memo[key] ||= begin
|
39
40
|
lookup = prefactory_lookup(key)
|
40
41
|
if lookup.present?
|
41
|
-
lookup[:result_class]
|
42
|
+
if lookup[:result_class]
|
43
|
+
lookup[:result_class].constantize.find(lookup[:result_id])
|
44
|
+
else
|
45
|
+
YAML.load(lookup[:result_value])
|
46
|
+
end
|
42
47
|
else
|
43
48
|
Prefactory::NotDefined
|
44
49
|
end
|
@@ -62,10 +67,20 @@ module Prefactory
|
|
62
67
|
result = create(key, *args) if respond_to?(:create)
|
63
68
|
end
|
64
69
|
if result.present?
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
if result.respond_to?(:id)
|
71
|
+
PrefactoryLookup.where(:key => key).first_or_initialize.tap do |lookup|
|
72
|
+
lookup.result_class = result.class.name
|
73
|
+
lookup.result_id = result.id
|
74
|
+
lookup.result_value = nil
|
75
|
+
lookup.save!
|
76
|
+
end
|
77
|
+
else
|
78
|
+
PrefactoryLookup.where(:key => key).first_or_initialize.tap do |lookup|
|
79
|
+
lookup.result_class = nil
|
80
|
+
lookup.result_id = nil
|
81
|
+
lookup.result_value = YAML.dump(result)
|
82
|
+
lookup.save!
|
83
|
+
end
|
69
84
|
end
|
70
85
|
else
|
71
86
|
warn "WARNING: Failed to add #{key} to prefactory: block result not present"
|
data/spec/database_setup.rb
CHANGED
@@ -25,24 +25,25 @@ require 'erb'
|
|
25
25
|
config = YAML.load(ERB.new(File.read(File.dirname(__FILE__) + '/database.yml')).result)
|
26
26
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
27
27
|
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
28
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks)
|
28
29
|
|
29
30
|
ActiveRecord::Schema.define(:version => 2) do
|
30
31
|
create_table :blogs, :force => true do |t|
|
31
32
|
t.column :title, :string
|
32
33
|
t.column :counter, :integer
|
33
|
-
t.timestamps
|
34
|
+
t.timestamps :null => false
|
34
35
|
end
|
35
36
|
create_table :comments, :force => true do |t|
|
36
37
|
t.column :blog_id, :integer
|
37
38
|
t.column :counter, :integer
|
38
39
|
t.column :text, :string
|
39
|
-
t.timestamps
|
40
|
+
t.timestamps :null => false
|
40
41
|
end
|
41
42
|
create_table :links, :force => true do |t|
|
42
43
|
t.column :blog_id, :integer
|
43
44
|
t.column :counter, :integer
|
44
45
|
t.column :name, :string
|
45
|
-
t.timestamps
|
46
|
+
t.timestamps :null => false
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
data/spec/prefactory_spec.rb
CHANGED
@@ -118,6 +118,15 @@ describe Prefactory do
|
|
118
118
|
expect(some_other_blog.counter).to eq(24)
|
119
119
|
end
|
120
120
|
end
|
121
|
+
context 'when the block returns something that does not respond_to? :id' do
|
122
|
+
before :all do
|
123
|
+
prefactory_add(:freeze_time) { Time.parse('2015-09-13 17:15') }
|
124
|
+
end
|
125
|
+
it do
|
126
|
+
expect(freeze_time).to be_a Time
|
127
|
+
expect(freeze_time).to eq Time.parse('2015-09-13 17:15')
|
128
|
+
end
|
129
|
+
end
|
121
130
|
context "when referencing the object within the before-all block" do
|
122
131
|
before :all do
|
123
132
|
prefactory_add :blog
|
@@ -198,7 +207,7 @@ describe Prefactory do
|
|
198
207
|
expect(@before_each_exception).to be_present
|
199
208
|
end
|
200
209
|
it "raises an error in an it-context" do
|
201
|
-
expect { prefactory_add(:comment) }.to raise_error
|
210
|
+
expect { prefactory_add(:comment) }.to raise_error(/can only be used in a before\(:all\)/)
|
202
211
|
end
|
203
212
|
it "works in a before-all context" do
|
204
213
|
expect(prefactory(:blog)).to be_present
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- developers@socialcast.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec_around_all
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.4.8
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: Transaction-wrapped RSpec example groups with FactoryGirl integration
|