with_model 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb1eb5e067e816d4644cde5fa9da460fd764ac36
4
+ data.tar.gz: 5de4c0d4f74cf020b4c6541b31fdcdb3ac4d053b
5
+ SHA512:
6
+ metadata.gz: 809520bde82da03692043a5e3b23bce6ceaffcaba26db542e4dec5380658bc00551ea8c6504d04c2a702a5983397d7a047596558926d79c0616f9296332a8b8c
7
+ data.tar.gz: e64fcb0db081580c10cd54f0b15f4ccde04fdadc5dd92edef5cc3944d68c7a54bb965b4a811f99999042402ee0d4d6c733929b03c3a02d4152d166a5619ceeca
@@ -1,8 +1,30 @@
1
+ language: ruby
2
+
3
+ script: "bundle exec rspec spec"
4
+
1
5
  rvm:
2
6
  - 1.8.7
3
- - 1.9.2
4
7
  - 1.9.3
8
+ - 2.0.0
9
+ - jruby-18mode
10
+ - jruby-19mode
5
11
  - rbx-18mode
6
12
  - rbx-19mode
7
13
  - ree
8
- script: "rake spec"
14
+
15
+ env:
16
+ - ACTIVE_RECORD_VERSION="~> 4.0.0.rc1"
17
+ - ACTIVE_RECORD_VERSION="~> 3.2.0"
18
+ - ACTIVE_RECORD_VERSION="~> 3.1.0"
19
+ - ACTIVE_RECORD_VERSION="~> 3.0.0"
20
+
21
+ matrix:
22
+ allow_failures:
23
+ - env: ACTIVE_RECORD_VERSION="~> 4.0.0.rc1"
24
+ exclude:
25
+ - rvm:
26
+ - 1.8.7
27
+ - jruby-18mode
28
+ - rbx-18mode
29
+ - ree
30
+ env: ACTIVE_RECORD_VERSION="~> 4.0.0.rc1"
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.3.2
2
+
3
+ Allow calling with_model without a block. (Andrew Marshall)
4
+ Ensure that ActiveSupport's descendants works correctly between tests. (Andrew Marshall)
5
+ Allow Active Record 4 in gemspec.
6
+
1
7
  ### 0.3.1
2
8
 
3
9
  Don't cache connection between tests. (Ryan Ong & Richard Nuno)
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
5
  gem "rake"
6
6
  gem "sqlite3", :platforms => :ruby
7
7
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rdoc"
9
+ gem 'coveralls', :require => false, :platform => :mri_20
10
+ gem 'activerecord', ENV["ACTIVE_RECORD_VERSION"] if ENV["ACTIVE_RECORD_VERSION"]
@@ -2,7 +2,10 @@
2
2
 
3
3
  * http://github.com/casecommons/with_model/
4
4
 
5
- {<img src="https://secure.travis-ci.org/Casecommons/with_model.png" />}[http://travis-ci.org/Casecommons/with_model] {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/Casecommons/with_model]
5
+ {<img src="https://secure.travis-ci.org/Casecommons/with_model.png" />}[http://travis-ci.org/Casecommons/with_model]
6
+ {<img src="https://gemnasium.com/Casecommons/with_model.png" alt="Dependency Status" />}[https://gemnasium.com/Casecommons/with_model]
7
+ {<img src="https://codeclimate.com/github/Casecommons/with_model.png" />}[https://codeclimate.com/github/Casecommons/with_model]
8
+ {<img src="https://coveralls.io/repos/Casecommons/with_model/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/Casecommons/with_model]
6
9
 
7
10
  == DESCRIPTION
8
11
 
@@ -4,7 +4,9 @@ module WithModel
4
4
  autoload :VERSION, "with_model/version"
5
5
 
6
6
  def with_model(name, &block)
7
- Dsl.new(name, self).tap { |dsl| dsl.instance_eval(&block) }.execute
7
+ dsl = Dsl.new(name, self)
8
+ dsl.instance_eval(&block) if block
9
+ dsl.execute
8
10
  end
9
11
 
10
12
  def with_table(name, options = {}, &block)
@@ -41,6 +41,9 @@ module WithModel
41
41
  end
42
42
 
43
43
  @example_group.after do
44
+ if model.superclass.respond_to?(:direct_descendants)
45
+ model.superclass.direct_descendants.delete(model)
46
+ end
44
47
  if defined?(ActiveSupport::Dependencies::Reference)
45
48
  ActiveSupport::Dependencies::Reference.clear!
46
49
  end
@@ -1,3 +1,3 @@
1
1
  module WithModel
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -2,17 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe "ActiveRecord behaviors" do
4
4
  describe "a temporary ActiveRecord model created with with_model" do
5
- context "that has a named_scope" do
5
+ context "that has a named scope" do
6
6
  before do
7
7
  class RegularModel < ActiveRecord::Base
8
- scope_method =
9
- if respond_to?(:scope) && !protected_methods.include?('scope')
10
- :scope # ActiveRecord 3.x
11
- else
12
- :named_scope # ActiveRecord 2.x
13
- end
14
-
15
- send scope_method, :title_is_foo, :conditions => {:title => 'foo'}
8
+ scope :title_is_foo, lambda { where(:title => 'foo') }
16
9
  end
17
10
  RegularModel.connection.drop_table(RegularModel.table_name) rescue nil
18
11
  RegularModel.connection.create_table(RegularModel.table_name) do |t|
@@ -34,14 +27,7 @@ describe "ActiveRecord behaviors" do
34
27
  end
35
28
 
36
29
  model do
37
- scope_method =
38
- if respond_to?(:scope) && !protected_methods.include?('scope')
39
- :scope # ActiveRecord 3.x
40
- else
41
- :named_scope # ActiveRecord 2.x
42
- end
43
-
44
- send scope_method, :title_is_foo, :conditions => {:title => 'foo'}
30
+ scope :title_is_foo, lambda { where(:title => 'foo') }
45
31
  end
46
32
  end
47
33
 
@@ -1,6 +1,12 @@
1
1
  require "active_record"
2
2
  require "with_model"
3
3
 
4
+ begin
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ rescue LoadError
8
+ end
9
+
4
10
  RSpec.configure do |config|
5
11
  config.extend WithModel
6
12
  end
@@ -76,8 +76,7 @@ describe "a temporary ActiveRecord model created with with_model" do
76
76
  shadowing_example_ran = false
77
77
 
78
78
  describe "that shadows an existing constant" do
79
- with_model :MyConst do
80
- end
79
+ with_model :MyConst
81
80
 
82
81
  after do
83
82
  shadowing_example_ran = true
@@ -96,8 +95,7 @@ describe "a temporary ActiveRecord model created with with_model" do
96
95
  end
97
96
 
98
97
  describe "with a plural name" do
99
- with_model :BlogPosts do
100
- end
98
+ with_model :BlogPosts
101
99
 
102
100
  it "should not singularize the constant name" do
103
101
  BlogPosts.should be
@@ -106,8 +104,7 @@ describe "a temporary ActiveRecord model created with with_model" do
106
104
  end
107
105
 
108
106
  describe "with a name containing capital letters" do
109
- with_model :BlogPost do
110
- end
107
+ with_model :BlogPost
111
108
 
112
109
  it "should tableize the table name" do
113
110
  BlogPost.table_name.should match(/_blog_posts_/)
@@ -116,8 +113,7 @@ describe "a temporary ActiveRecord model created with with_model" do
116
113
  end
117
114
 
118
115
  describe "with a name with underscores" do
119
- with_model :blog_post do
120
- end
116
+ with_model :blog_post
121
117
 
122
118
  it "should constantize the name" do
123
119
  BlogPost.should be
@@ -200,6 +196,46 @@ describe "a temporary ActiveRecord model created with with_model" do
200
196
  end
201
197
  end
202
198
 
199
+ context "without a block" do
200
+ with_model :BlogPost
201
+
202
+ it "should act like a normal ActiveRecord model" do
203
+ record = BlogPost.create!
204
+ record.reload
205
+ record.destroy
206
+ lambda {
207
+ record.reload
208
+ }.should raise_error(ActiveRecord::RecordNotFound)
209
+ end
210
+
211
+ if defined?(ActiveModel)
212
+ describe "the class" do
213
+ subject { BlogPost.new }
214
+ it_should_behave_like "ActiveModel"
215
+ end
216
+ end
217
+ end
218
+
219
+ context "with an empty block" do
220
+ with_model(:BlogPost) {}
221
+
222
+ it "should act like a normal ActiveRecord model" do
223
+ record = BlogPost.create!
224
+ record.reload
225
+ record.destroy
226
+ lambda {
227
+ record.reload
228
+ }.should raise_error(ActiveRecord::RecordNotFound)
229
+ end
230
+
231
+ if defined?(ActiveModel)
232
+ describe "the class" do
233
+ subject { BlogPost.new }
234
+ it_should_behave_like "ActiveModel"
235
+ end
236
+ end
237
+ end
238
+
203
239
  context "without a model block" do
204
240
  with_model :BlogPost do
205
241
  table do |t|
@@ -255,4 +291,20 @@ describe "a temporary ActiveRecord model created with with_model" do
255
291
  end
256
292
  end
257
293
  end
294
+
295
+ context "with ActiveSupport::DescendantsTracker" do
296
+ with_model :BlogPost
297
+
298
+ it "includes the correct model class in descendants on the first test run" do
299
+ ActiveRecord::Base.descendants.detect do |c|
300
+ c.table_name == BlogPost.table_name
301
+ end.should == BlogPost
302
+ end
303
+
304
+ it "includes the correct model class in descendants on the second test run" do
305
+ ActiveRecord::Base.descendants.detect do |c|
306
+ c.table_name == BlogPost.table_name
307
+ end.should == BlogPost
308
+ end
309
+ end
258
310
  end
@@ -11,12 +11,13 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "https://github.com/Casecommons/with_model"
12
12
  s.summary = %q{Dynamically build a model within an RSpec context}
13
13
  s.description = s.summary
14
+ s.licenses = ["MIT"]
14
15
 
15
16
  s.files = `git ls-files`.split("\n")
16
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
19
  s.require_paths = ["lib"]
19
20
 
20
- s.add_dependency 'activerecord', '>=2.3.5', '<4.0.0'
21
+ s.add_dependency 'activerecord', '>=2.3.5', '<5.0.0'
21
22
  s.add_dependency 'rspec', "~>2.11"
22
23
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 0.3.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Case Commons, LLC
@@ -10,34 +9,31 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-10-08 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 2.3.5
23
21
  - - <
24
22
  - !ruby/object:Gem::Version
25
- version: 4.0.0
23
+ version: 5.0.0
26
24
  type: :runtime
27
25
  prerelease: false
28
26
  version_requirements: !ruby/object:Gem::Requirement
29
- none: false
30
27
  requirements:
31
- - - ! '>='
28
+ - - '>='
32
29
  - !ruby/object:Gem::Version
33
30
  version: 2.3.5
34
31
  - - <
35
32
  - !ruby/object:Gem::Version
36
- version: 4.0.0
33
+ version: 5.0.0
37
34
  - !ruby/object:Gem::Dependency
38
35
  name: rspec
39
36
  requirement: !ruby/object:Gem::Requirement
40
- none: false
41
37
  requirements:
42
38
  - - ~>
43
39
  - !ruby/object:Gem::Version
@@ -45,7 +41,6 @@ dependencies:
45
41
  type: :runtime
46
42
  prerelease: false
47
43
  version_requirements: !ruby/object:Gem::Requirement
48
- none: false
49
44
  requirements:
50
45
  - - ~>
51
46
  - !ruby/object:Gem::Version
@@ -77,34 +72,28 @@ files:
77
72
  - spec/with_model_spec.rb
78
73
  - with_model.gemspec
79
74
  homepage: https://github.com/Casecommons/with_model
80
- licenses: []
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
81
78
  post_install_message:
82
79
  rdoc_options: []
83
80
  require_paths:
84
81
  - lib
85
82
  required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
83
  requirements:
88
- - - ! '>='
84
+ - - '>='
89
85
  - !ruby/object:Gem::Version
90
86
  version: '0'
91
- segments:
92
- - 0
93
- hash: -4572723804950659860
94
87
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
88
  requirements:
97
- - - ! '>='
89
+ - - '>='
98
90
  - !ruby/object:Gem::Version
99
91
  version: '0'
100
- segments:
101
- - 0
102
- hash: -4572723804950659860
103
92
  requirements: []
104
93
  rubyforge_project:
105
- rubygems_version: 1.8.24
94
+ rubygems_version: 2.0.0
106
95
  signing_key:
107
- specification_version: 3
96
+ specification_version: 4
108
97
  summary: Dynamically build a model within an RSpec context
109
98
  test_files:
110
99
  - spec/active_record_behaviors_spec.rb