warp 1.3.1 → 1.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6cbf9ef52e08774d01f175a2332feeb01860963
4
- data.tar.gz: 30b1477e764a15f0bf98fff122558e7adbd9a4c6
3
+ metadata.gz: 7b1b1e989d088f3bbda7a83d127547473043ee8e
4
+ data.tar.gz: f573120f00d484663e0a6d7aa86f431dcb58e04e
5
5
  SHA512:
6
- metadata.gz: 451e896e044e7c5cd8f22f1f766c7f338eaf7f5826e27d2e65dbe7344eda07ec75a261ecdd1f89dc35048439b039e00e732c992545555f527a6e98f168433792
7
- data.tar.gz: 44f2d8b79a1fc65ee0a8bde854ed658b7db548dd0e1e0396968a2ab27933ad5dd029f1785d807332f870678e0530d522079de5f09d3f9ce3d73fecd84c23c24a
6
+ metadata.gz: b741742b5f1c7591651a413c68d29dbb5f081cf30d1ff4d2729ed582e278bc81aa19bea725f4209b504d8d42d38e6df4dc9d6b3fe73ed9c5b31a8d85910dee4f
7
+ data.tar.gz: 0224f05bd32daf3d0277f6eed683a87b113e68d7629915c646bcf2b66d3c6018f5ed157f7ae3853ade9101a17b02221c65bdbc2b3f4ea39e7876e051304a7046
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ - 1.3.2
2
+ - Added model deletion matcher.
3
+
4
+ - 1.3.1
5
+ - Fixed issue where model creation matcher would unconditionally pass on subsequent matches.
6
+
7
+ - 1.3.0
8
+ - Matchers are now only included into relevant spec types.
9
+ - Matchers can now be individually required.
10
+ - Added model creation matcher.
11
+
1
12
  - 1.2.3
2
13
  - Now compatible with Rails 4.2.
3
14
 
@@ -18,4 +29,4 @@
18
29
  - Fixed issue where matchers would error unless explicitly passed the controller object.
19
30
 
20
31
  - 1.0.0
21
- - Initial release
32
+ - Initial release
data/Gemfile CHANGED
@@ -5,14 +5,14 @@ gemspec
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
7
 
8
+ gem "jamjar"
9
+
8
10
  gem "rake"
9
11
  gem "fuubar"
10
12
 
11
13
  gem "simplecov", require: false
12
14
  gem "coveralls", require: false
13
15
 
14
- gem "activerecord-nulldb-adapter", require: false
15
-
16
16
  group :tools do
17
17
  gem "guard"
18
18
  gem "guard-rspec"
data/README.md CHANGED
@@ -220,7 +220,7 @@ specify { expect(user).to validate_uniqueness_of(:email, scope: :company) }
220
220
 
221
221
  ### Creation Matchers
222
222
 
223
- #### creates
223
+ #### create
224
224
 
225
225
  Ensures that a record is created.
226
226
 
@@ -228,6 +228,14 @@ Ensures that a record is created.
228
228
  specify { expect{post :create, params}.to create(Post) }
229
229
  ```
230
230
 
231
+ #### destroy
232
+
233
+ Ensures that a record is destroyed.
234
+
235
+ ```ruby
236
+ specify { expect{delete :destroy, id: id}.to destroy(Post) }
237
+ ```
238
+
231
239
  ## Contributing
232
240
 
233
241
  1. Fork it
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 3.2", :require => "active_support/all"
13
13
  gem "actionpack", "~> 3.2", :require => "action_controller"
14
14
  gem "activerecord", "~> 3.2", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 3.2", :require => "active_support/all"
13
13
  gem "actionpack", "~> 3.2", :require => "action_controller"
14
14
  gem "activerecord", "~> 3.2", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 3.2", :require => "active_support/all"
13
13
  gem "actionpack", "~> 3.2", :require => "action_controller"
14
14
  gem "activerecord", "~> 3.2", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.0", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.0", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.0", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.0", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.0", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.0", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.0", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.0", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.0", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.1", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.1", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.1", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.1", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.1", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.1", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.1", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.1", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.1", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.2.rc1", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.2.rc1", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.2.rc1", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.2.rc1", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.2.rc1", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.2.rc1", :require => "active_record"
@@ -4,11 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "bundler"
6
6
  gem "appraisal"
7
+ gem "jamjar"
7
8
  gem "rake"
8
9
  gem "fuubar"
9
10
  gem "simplecov", :require => false
10
11
  gem "coveralls", :require => false
11
- gem "activerecord-nulldb-adapter", :require => false
12
12
  gem "activesupport", "~> 4.2.rc1", :require => "active_support/all"
13
13
  gem "actionpack", "~> 4.2.rc1", :require => "action_controller"
14
14
  gem "activerecord", "~> 4.2.rc1", :require => "active_record"
@@ -3,6 +3,7 @@ unless defined?(ActiveModel)
3
3
  end
4
4
 
5
5
  require "warp/action_matchers/create_matcher"
6
+ require "warp/action_matchers/destroy_matcher"
6
7
 
7
8
  RSpec.configure do |config|
8
9
  config.include Warp::ActionMatchers
@@ -17,9 +17,7 @@ module Warp
17
17
  end
18
18
 
19
19
  def matches?(actual)
20
- unless actual.respond_to?(:call)
21
- raise "The create matcher can only match against callables."
22
- end
20
+ check_callable!(actual)
23
21
 
24
22
  instrument = Warp::Instrument.for(model, CREATE_METHOD)
25
23
 
@@ -30,15 +28,15 @@ module Warp
30
28
  end
31
29
 
32
30
  def description
33
- "create a #{model.name}"
31
+ "create a #{model_name}"
34
32
  end
35
33
 
36
34
  def failure_message
37
- "expected a #{model.name} to be created"
35
+ "expected a #{model_name} to be created"
38
36
  end
39
37
 
40
38
  def failure_message_when_negated
41
- "expected no #{model.name} to be created"
39
+ "expected no #{model_name} to be created"
42
40
  end
43
41
  end
44
42
 
@@ -0,0 +1,47 @@
1
+ require "warp/action_matchers/matcher"
2
+ require "warp/instrument"
3
+
4
+ module Warp
5
+ module ActionMatchers
6
+ class DestroyMatcher < Warp::ActionMatchers::Matcher
7
+ if ActiveRecord::Base.private_method_defined?(:destroy_row)
8
+ DESTROY_METHOD = :destroy_row
9
+ else
10
+ DESTROY_METHOD = :destroy
11
+ end
12
+
13
+ attr_reader :model
14
+
15
+ def initialize(model)
16
+ @model = model
17
+ end
18
+
19
+ def matches?(actual)
20
+ check_callable!(actual)
21
+
22
+ instrument = Warp::Instrument.for(model, DESTROY_METHOD)
23
+
24
+ instrument.reset
25
+ instrument.run { actual.call }
26
+
27
+ instrument.calls.size > 0
28
+ end
29
+
30
+ def description
31
+ "destroy a #{model_name}"
32
+ end
33
+
34
+ def failure_message
35
+ "expected a #{model_name} to be destroyed"
36
+ end
37
+
38
+ def failure_message_when_negated
39
+ "expected no #{model_name} to be destroyed"
40
+ end
41
+ end
42
+
43
+ def destroy(model)
44
+ DestroyMatcher.new(model)
45
+ end
46
+ end
47
+ end
@@ -3,9 +3,17 @@ require "warp/matcher"
3
3
  module Warp
4
4
  module ActionMatchers
5
5
  class Matcher < Warp::Matcher
6
-
7
6
  private
8
7
 
8
+ def check_callable!(object)
9
+ unless object.respond_to?(:call)
10
+ raise "#{self.class.name} can only match against callables."
11
+ end
12
+ end
13
+
14
+ def model_name
15
+ model.model_name.to_s
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -16,7 +16,7 @@ module Warp
16
16
  end
17
17
  end
18
18
 
19
- attr_accessor :klass, :method, :hook, :enabled, :calls
19
+ attr_accessor :klass, :method, :enabled, :calls
20
20
 
21
21
  def initialize(klass, method)
22
22
  self.klass = klass
@@ -58,14 +58,16 @@ module Warp
58
58
 
59
59
  def setup_hook
60
60
  if Module.method_defined?(:prepend)
61
- self.hook = Module.new
61
+ hook = Module.new
62
62
 
63
63
  hook.send(:define_method, method) do |*args|
64
+ result = super(*args)
65
+
64
66
  if Warp::Instrument.for(self.class, __method__).enabled?
65
- Warp::Instrument.for(self.class, __method__).log(args)
67
+ Warp::Instrument.for(self.class, __method__).log([args, result])
66
68
  end
67
69
 
68
- super(*args)
70
+ return result
69
71
  end
70
72
 
71
73
  klass.prepend(hook)
@@ -73,11 +75,13 @@ module Warp
73
75
  original_method = klass.instance_method(method)
74
76
 
75
77
  klass.send(:define_method, method) do |*args|
78
+ result = original_method.bind(self).call(*args)
79
+
76
80
  if Warp::Instrument.for(self.class, __method__).enabled?
77
- Warp::Instrument.for(self.class, __method__).log(args)
81
+ Warp::Instrument.for(self.class, __method__).log([args, result])
78
82
  end
79
83
 
80
- original_method.bind(self).call(*args)
84
+ return result
81
85
  end
82
86
  end
83
87
  end
@@ -16,7 +16,7 @@ module Warp
16
16
  end
17
17
 
18
18
  def model_name
19
- model.name
19
+ model.model_name.to_s
20
20
  end
21
21
  end
22
22
  end
data/lib/warp/version.rb CHANGED
@@ -2,7 +2,7 @@ module Warp
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 3
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  BETA = nil
8
8
 
data/spec/spec_helper.rb CHANGED
@@ -33,17 +33,13 @@ if defined?(Rails) && !Rails.respond_to?(:env)
33
33
  end
34
34
  end
35
35
 
36
- require "activerecord-nulldb-adapter"
37
- ActiveRecord::Base.establish_connection adapter: :nulldb
38
-
39
36
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
40
37
 
41
38
  RSpec.configure do |config|
42
- config.order = 'random'
39
+ config.order = "random"
43
40
 
44
41
  config.extend ControllerHelpers
45
42
  config.extend FailureMessageHelpers
46
- config.extend ModelHelpers
47
43
  config.extend WithContextsHelpers
48
44
  config.include MatchHelpers
49
45
  end
@@ -1,10 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Warp::ActionMatchers::CreateMatcher do
4
- build_model do
5
- column :foo
4
+ let(:model) do
5
+ JamJar.model do
6
+ column :foo, :string
6
7
 
7
- validates :foo, presence: true
8
+ validates :foo, presence: true
9
+ end
8
10
  end
9
11
 
10
12
  before { Warp::Instrument.for(model, Warp::ActionMatchers::CreateMatcher::CREATE_METHOD).calls << Object.new }
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Warp::ActionMatchers::DestroyMatcher do
4
+ let(:model) { JamJar.model }
5
+
6
+ let!(:instance) { model.create }
7
+
8
+ before { Warp::Instrument.for(model, Warp::ActionMatchers::DestroyMatcher::DESTROY_METHOD).calls << Object.new }
9
+
10
+ subject { destroy(model) }
11
+
12
+ with_contexts do
13
+ context "when destroyed with #destroy" do
14
+ let(:block) { -> { instance.destroy } }
15
+ end
16
+
17
+ context "when destroyed with #destroy_all" do
18
+ let(:block) { -> { model.destroy_all } }
19
+ end
20
+
21
+ behaviour do
22
+ specify { expect(subject).to match block }
23
+ end
24
+ end
25
+
26
+ context "when nothing destroyed" do
27
+ let(:block) { -> { return } }
28
+
29
+ specify { expect(subject).to_not match block }
30
+ end
31
+
32
+ describe "#desciption" do
33
+ subject { super().description }
34
+
35
+ specify { expect(subject).to eq "destroy a TestModel" }
36
+ end
37
+
38
+ describe_failure_message do
39
+ specify { expect(subject).to eq "expected a TestModel to be destroyed" }
40
+ end
41
+
42
+ describe_failure_message_when_negated do
43
+ specify { expect(subject).to eq "expected no TestModel to be destroyed" }
44
+ end
45
+ end
@@ -3,10 +3,13 @@ require "spec_helper"
3
3
  describe Warp::Instrument do
4
4
  let(:klass) { Class.new }
5
5
  let(:method) { :foo }
6
+ let(:result) { Object.new }
6
7
  let(:instrument) { Warp::Instrument.for(klass, method) }
7
8
 
8
9
  before do
9
- klass.send(:define_method, method) {|*_| return nil }
10
+ klass.class_eval { cattr_accessor :result }
11
+ klass.result = result
12
+ klass.send(:define_method, method) {|*_| return result }
10
13
  end
11
14
 
12
15
  describe ".for" do
@@ -44,7 +47,7 @@ describe Warp::Instrument do
44
47
  end
45
48
 
46
49
  context "when a call has been logged" do
47
- let(:args) { [{baz: :quz}] }
50
+ let(:args) { [12, {baz: :quz}] }
48
51
 
49
52
  before do
50
53
  instrument.run do
@@ -52,7 +55,7 @@ describe Warp::Instrument do
52
55
  end
53
56
  end
54
57
 
55
- specify { expect(subject).to eq [args] }
58
+ specify { expect(subject).to eq [[args, result]] }
56
59
  end
57
60
  end
58
61
  end
@@ -1,11 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Warp::ModelMatchers::AssociationMatcher, type: :model do
4
- build_model do
5
- belongs_to :foo
6
- has_many :bars
7
- has_one :baz
8
- has_and_belongs_to_many :qux
4
+ let(:model) do
5
+ JamJar.model do
6
+ belongs_to :foo
7
+ has_many :bars
8
+ has_one :baz
9
+ has_and_belongs_to_many :qux
10
+ end
9
11
  end
10
12
 
11
13
  with_contexts do
@@ -1,8 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Warp::ModelMatchers::AttributeMatcher, type: :model do
4
- build_model do
5
- column :foo
4
+ let(:model) do
5
+ JamJar.model do
6
+ column :foo, :string
7
+ end
6
8
  end
7
9
 
8
10
  with_contexts do
@@ -1,8 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Warp::ModelMatchers::ValidationMatcher, type: :model do
4
- build_model do
5
- column :foo
4
+ let(:model) do
5
+ JamJar.model do
6
+ column :foo, :string
7
+ end
6
8
  end
7
9
 
8
10
  let(:attr_name) { :foo }
data/warp.gemspec CHANGED
@@ -17,5 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(spec)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
+ spec.required_ruby_version = ">= 1.9.2"
21
+
20
22
  spec.add_runtime_dependency "rspec", ">= 2.14.0"
21
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Drake-Brockman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -59,6 +59,7 @@ files:
59
59
  - lib/warp.rb
60
60
  - lib/warp/action_matchers.rb
61
61
  - lib/warp/action_matchers/create_matcher.rb
62
+ - lib/warp/action_matchers/destroy_matcher.rb
62
63
  - lib/warp/action_matchers/matcher.rb
63
64
  - lib/warp/controller_matchers.rb
64
65
  - lib/warp/controller_matchers/assign_matcher.rb
@@ -76,9 +77,9 @@ files:
76
77
  - spec/support/controller_helpers.rb
77
78
  - spec/support/failure_message_helpers.rb
78
79
  - spec/support/match_helpers.rb
79
- - spec/support/model_helpers.rb
80
80
  - spec/support/with_contexts_helpers.rb
81
81
  - spec/warp/action_matchers/create_matcher_spec.rb
82
+ - spec/warp/action_matchers/destroy_matcher_spec.rb
82
83
  - spec/warp/controller_matchers/assign_matcher_spec.rb
83
84
  - spec/warp/controller_matchers/set_flash_matcher_spec.rb
84
85
  - spec/warp/instrument_spec.rb
@@ -98,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
100
  - - ">="
100
101
  - !ruby/object:Gem::Version
101
- version: '0'
102
+ version: 1.9.2
102
103
  required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
105
  - - ">="
@@ -115,9 +116,9 @@ test_files:
115
116
  - spec/support/controller_helpers.rb
116
117
  - spec/support/failure_message_helpers.rb
117
118
  - spec/support/match_helpers.rb
118
- - spec/support/model_helpers.rb
119
119
  - spec/support/with_contexts_helpers.rb
120
120
  - spec/warp/action_matchers/create_matcher_spec.rb
121
+ - spec/warp/action_matchers/destroy_matcher_spec.rb
121
122
  - spec/warp/controller_matchers/assign_matcher_spec.rb
122
123
  - spec/warp/controller_matchers/set_flash_matcher_spec.rb
123
124
  - spec/warp/instrument_spec.rb
@@ -1,41 +0,0 @@
1
- module ModelHelpers
2
- def build_model(&blk)
3
- let(:model) do
4
- Class.new(ActiveRecord::Base) do
5
- attr_accessor :id
6
-
7
- def self.name
8
- "TestModel"
9
- end
10
-
11
- def self.primary_key
12
- "id"
13
- end
14
-
15
- def self.columns
16
- @columns ||= []
17
- end
18
-
19
- def self.attribute_names
20
- @columns.map(&:name)
21
- end
22
-
23
- def self.attribute_method?(method)
24
- method = method.to_s.sub("=", "")
25
- columns.any? {|c| c.name == method }
26
- end
27
-
28
- def self.column(name, sql_type = "varchar(255)", default = nil, null = true)
29
- if ActiveRecord::ConnectionAdapters::AbstractAdapter.method_defined?(:lookup_cast_type)
30
- cast_type = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil, nil, nil).lookup_cast_type(sql_type)
31
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, cast_type, sql_type.to_s, null)
32
- else
33
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
34
- end
35
- end
36
-
37
- instance_eval(&blk) if blk
38
- end
39
- end
40
- end
41
- end