with_model 0.3.2 → 1.0.0

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.
@@ -1,23 +1,29 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "with_model/version"
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'with_model/version'
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = "with_model"
7
- s.version = WithModel::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Case Commons, LLC", "Grant Hutchins"]
10
- s.email = ["casecommons-dev@googlegroups.com", "gems@nertzy.com"]
11
- s.homepage = "https://github.com/Casecommons/with_model"
12
- s.summary = %q{Dynamically build a model within an RSpec context}
13
- s.description = s.summary
14
- s.licenses = ["MIT"]
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'with_model'
7
+ spec.version = WithModel::VERSION
8
+ spec.authors = ['Case Commons, LLC', 'Grant Hutchins']
9
+ spec.email = ['casecommons-dev@googlegroups.com', 'gems@nertzy.com', 'andrew@johnandrewmarshall.com']
10
+ spec.homepage = 'https://github.com/Casecommons/with_model'
11
+ spec.summary = %q(Dynamically build a model within an RSpec context)
12
+ spec.description = spec.summary
13
+ spec.license = 'MIT'
15
14
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
20
19
 
21
- s.add_dependency 'activerecord', '>=2.3.5', '<5.0.0'
22
- s.add_dependency 'rspec', "~>2.11"
20
+ spec.required_ruby_version = '>= 1.9.3'
21
+
22
+ spec.add_dependency 'activerecord', '>= 3.0', '< 4.1'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '~> 2.14'
27
+ spec.add_development_dependency 'rubysl' if RUBY_ENGINE == 'rbx'
28
+ spec.add_development_dependency 'rubysl-test-unit' if RUBY_ENGINE == 'rbx'
23
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Case Commons, LLC
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-08 00:00:00.000000000 Z
12
+ date: 2014-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,54 +17,85 @@ dependencies:
17
17
  requirements:
18
18
  - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: 2.3.5
20
+ version: '3.0'
21
21
  - - <
22
22
  - !ruby/object:Gem::Version
23
- version: 5.0.0
23
+ version: '4.1'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - '>='
29
29
  - !ruby/object:Gem::Version
30
- version: 2.3.5
30
+ version: '3.0'
31
31
  - - <
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.0
33
+ version: '4.1'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
34
62
  - !ruby/object:Gem::Dependency
35
63
  name: rspec
36
64
  requirement: !ruby/object:Gem::Requirement
37
65
  requirements:
38
66
  - - ~>
39
67
  - !ruby/object:Gem::Version
40
- version: '2.11'
41
- type: :runtime
68
+ version: '2.14'
69
+ type: :development
42
70
  prerelease: false
43
71
  version_requirements: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ~>
46
74
  - !ruby/object:Gem::Version
47
- version: '2.11'
75
+ version: '2.14'
48
76
  description: Dynamically build a model within an RSpec context
49
77
  email:
50
78
  - casecommons-dev@googlegroups.com
51
79
  - gems@nertzy.com
80
+ - andrew@johnandrewmarshall.com
52
81
  executables: []
53
82
  extensions: []
54
83
  extra_rdoc_files: []
55
84
  files:
56
- - .autotest
57
85
  - .gitignore
58
86
  - .rspec
59
87
  - .travis.yml
60
- - CHANGELOG
88
+ - CHANGELOG.md
61
89
  - Gemfile
62
90
  - LICENSE
63
- - README.rdoc
91
+ - README.md
64
92
  - Rakefile
65
93
  - lib/with_model.rb
66
- - lib/with_model/base.rb
67
- - lib/with_model/dsl.rb
94
+ - lib/with_model/constant_stubber.rb
95
+ - lib/with_model/methods.rb
96
+ - lib/with_model/model.rb
97
+ - lib/with_model/model/dsl.rb
98
+ - lib/with_model/table.rb
68
99
  - lib/with_model/version.rb
69
100
  - spec/active_record_behaviors_spec.rb
70
101
  - spec/readme_spec.rb
@@ -83,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
114
  requirements:
84
115
  - - '>='
85
116
  - !ruby/object:Gem::Version
86
- version: '0'
117
+ version: 1.9.3
87
118
  required_rubygems_version: !ruby/object:Gem::Requirement
88
119
  requirements:
89
120
  - - '>='
@@ -91,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
122
  version: '0'
92
123
  requirements: []
93
124
  rubyforge_project:
94
- rubygems_version: 2.0.0
125
+ rubygems_version: 2.0.14
95
126
  signing_key:
96
127
  specification_version: 4
97
128
  summary: Dynamically build a model within an RSpec context
data/.autotest DELETED
@@ -1,5 +0,0 @@
1
- Autotest.add_hook :initialize do |at|
2
- at.add_mapping(%r%^lib/.*\.rb$%, true) { |filename, _|
3
- at.files_matching %r%^spec/.*_spec.rb$%
4
- }
5
- end
data/CHANGELOG DELETED
@@ -1,62 +0,0 @@
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
-
7
- ### 0.3.1
8
-
9
- Don't cache connection between tests. (Ryan Ong & Richard Nuno)
10
-
11
- ### 0.3
12
-
13
- Use RSpec 2.11's built-in constant stubbing.
14
- Remove RSpec 1.x and Active Record 2.x support.
15
- Remove Mixico support.
16
-
17
- ### 0.2.6
18
-
19
- Active Record 3.2 compatible. (Steven Harman / Brent Wheeldon)
20
-
21
- ### 0.2.5
22
-
23
- Clear Active Record 3.x associations class cache between specs to clean up test
24
- pollution.
25
-
26
- ### 0.2.4
27
-
28
- Active Record 3.1 compatible.
29
- Fix bug where column information was being cached incorrectly by Active
30
- Record.
31
-
32
- ### 0.2.3
33
-
34
- Create a new class each run to prevent test pollution. (J. Andrew Marshall)
35
- Use :UpperCase in examples.
36
-
37
- ### 0.2.2
38
-
39
- The table block is now optional.
40
-
41
- ### 0.2.1
42
-
43
- Fix a bug when the with_model name contains capital letters. Now you can
44
- safely make calls like `with_model :BlogPost`
45
-
46
- ### 0.2
47
-
48
- Remove the buggy attr_accessor method for accessing with_model classes. Now
49
- there is only the constant available in the example group.
50
-
51
- ### 0.1.5
52
-
53
- WithModel::Base is now marked as an abstract_class, which makes polymorphic
54
- belongs_to work properly.
55
-
56
- ### 0.1.4
57
-
58
- Add ability to pass arguments to create_table.
59
-
60
- ### 0.1.2
61
-
62
- Make Mixico optional.
@@ -1,122 +0,0 @@
1
- = with_model
2
-
3
- * http://github.com/casecommons/with_model/
4
-
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]
9
-
10
- == DESCRIPTION
11
-
12
- +with_model+ dynamically builds an ActiveRecord model (with table) within an RSpec context. Outside of the context, the model is no longer present.
13
-
14
- == INSTALL
15
-
16
- gem install with_model
17
-
18
- In spec_helper.rb:
19
-
20
- RSpec.configure do |config|
21
- config.extend WithModel
22
- end
23
-
24
- == USAGE
25
-
26
- In an RSpec example group, call +with_model+ and inside its block pass it a +table+ block and a +model+ block.
27
-
28
- require 'spec_helper'
29
-
30
- describe "A blog post" do
31
-
32
- with_model :BlogPost do
33
- # The table block works just like a migration.
34
- table do |t|
35
- t.string :title
36
- t.timestamps
37
- end
38
-
39
- # The model block works just like the class definition.
40
- model do
41
- include SomeModule
42
- has_many :comments
43
- validates_presence_of :title
44
-
45
- def self.some_class_method
46
- 'chunky'
47
- end
48
-
49
- def some_instance_method
50
- 'bacon'
51
- end
52
- end
53
- end
54
-
55
- # with_model classes can have associations.
56
- with_model :Comment do
57
- table do |t|
58
- t.string :text
59
- t.belongs_to :blog_post
60
- t.timestamps
61
- end
62
-
63
- model do
64
- belongs_to :blog_post
65
- end
66
- end
67
-
68
- it "can be accessed as a constant" do
69
- BlogPost.should be
70
- end
71
-
72
- it "has the module" do
73
- BlogPost.include?(SomeModule).should be_true
74
- end
75
-
76
- it "has the class method" do
77
- BlogPost.some_class_method.should == 'chunky'
78
- end
79
-
80
- it "has the instance method" do
81
- BlogPost.new.some_instance_method.should == 'bacon'
82
- end
83
-
84
- it "can do all the things a regular model can" do
85
- record = BlogPost.new
86
- record.should_not be_valid
87
- record.title = "foo"
88
- record.should be_valid
89
- record.save.should be_true
90
- record.reload.should == record
91
- record.comments.create!(:text => "Lorem ipsum")
92
- record.comments.count.should == 1
93
- end
94
- end
95
-
96
- describe "another example group" do
97
- it "should not have the constant anymore" do
98
- defined?(BlogPost).should be_false
99
- end
100
- end
101
-
102
- describe "with table options" do
103
- with_model :WithOptions do
104
- table :id => false do |t|
105
- t.string 'foo'
106
- t.timestamps
107
- end
108
- end
109
-
110
- it "should respect the additional options" do
111
- WithOptions.columns.map(&:name).should_not include("id")
112
- end
113
- end
114
-
115
- == REQUIREMENTS
116
-
117
- * RSpec 2.11 or higher (for earlier RSpec versions, use 0.2.x)
118
- * ActiveRecord 3 (for ActiveRecord 2, use 0.2.x)
119
-
120
- == LICENSE:
121
-
122
- MIT
@@ -1,10 +0,0 @@
1
- module WithModel
2
- class Base < ActiveRecord::Base
3
- self.abstract_class = true
4
- class << self
5
- def with_model?
6
- true
7
- end
8
- end
9
- end
10
- end
@@ -1,53 +0,0 @@
1
- require 'active_support/inflector'
2
-
3
- module WithModel
4
- class Dsl
5
- NOOP = lambda {|*|}
6
-
7
- def initialize(name, example_group)
8
- @name = name
9
- @example_group = example_group
10
- @model_initialization = NOOP
11
- @table_block = NOOP
12
- @table_options = {}
13
- end
14
-
15
- def table(options = {}, &block)
16
- @table_options = options
17
- @table_block = block
18
- end
19
-
20
- def model(&block)
21
- @model_initialization = block
22
- end
23
-
24
- def execute
25
- model_initialization = @model_initialization
26
- const_name = @name.to_s.camelize
27
- table_name = "with_model_#{@name.to_s.tableize}_#{$$}"
28
-
29
- model = nil
30
-
31
- @example_group.with_table(table_name, @table_options, &@table_block)
32
-
33
- @example_group.before do
34
- model = Class.new(WithModel::Base)
35
- stub_const(const_name, model)
36
- model.class_eval do
37
- self.table_name = table_name
38
- self.class_eval(&model_initialization)
39
- end
40
- model.reset_column_information
41
- end
42
-
43
- @example_group.after do
44
- if model.superclass.respond_to?(:direct_descendants)
45
- model.superclass.direct_descendants.delete(model)
46
- end
47
- if defined?(ActiveSupport::Dependencies::Reference)
48
- ActiveSupport::Dependencies::Reference.clear!
49
- end
50
- end
51
- end
52
- end
53
- end