with_model 0.2.6 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,5 +4,5 @@ pkg/*
4
4
  .bundle
5
5
  .rvmrc
6
6
  doc
7
- gemfiles/**/Gemfile.lock
8
- *.rbc
7
+ Gemfile.lock
8
+ *.rbc
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ ### 0.3
2
+
3
+ Use RSpec 2.11's built-in constant stubbing.
4
+ Remove RSpec 1.x and Active Record 2.x support.
5
+ Remove Mixico support.
6
+
7
+ ### 0.2.6
8
+
9
+ Active Record 3.2 compatible. (Steven Harman / Brent Wheeldon)
10
+
1
11
  ### 0.2.5
2
12
 
3
13
  Clear Active Record 3.x associations class cache between specs to clean up test
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
- puts <<-MESSAGE
2
- This project uses multiple Gemfiles in subdirectories of ./gemfiles.
3
- The rake tasks automatically install these bundles as necessary. See rake -T.
4
- MESSAGE
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "sqlite3", :platforms => :ruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
@@ -2,7 +2,7 @@
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]
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]
6
6
 
7
7
  == DESCRIPTION
8
8
 
@@ -12,22 +12,12 @@
12
12
 
13
13
  gem install with_model
14
14
 
15
- === RSpec 2
16
-
17
15
  In spec_helper.rb:
18
16
 
19
17
  RSpec.configure do |config|
20
18
  config.extend WithModel
21
19
  end
22
20
 
23
- === Rspec 1
24
-
25
- In spec_helper.rb:
26
-
27
- Spec::Runner.configure do |config|
28
- config.extend WithModel
29
- end
30
-
31
21
  == USAGE
32
22
 
33
23
  In an RSpec example group, call +with_model+ and inside its block pass it a +table+ block and a +model+ block.
@@ -119,16 +109,10 @@ In an RSpec example group, call +with_model+ and inside its block pass it a +tab
119
109
  end
120
110
  end
121
111
 
122
- === Mixico
123
-
124
- If you have the +mixico+ gem installed, WithModel will automatically unmix any modules that were mixed into your model class. Without +mixico+, each module will hold a reference to the class for the remainder of your test suite.
125
-
126
- Usually unmixing isn't necessary, but it can be helpful if you use something like Module#included_in_classes (from Active Support 2.3) in a later test to ask a module which classes it has been mixed into.
127
-
128
112
  == REQUIREMENTS
129
113
 
130
- * RSpec
131
- * ActiveRecord 2 or 3
114
+ * RSpec 2.11 or higher (for earlier RSpec versions, use 0.2.x)
115
+ * ActiveRecord 3 (for ActiveRecord 2, use 0.2.x)
132
116
 
133
117
  == LICENSE:
134
118
 
data/Rakefile CHANGED
@@ -1,38 +1,15 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- environments = %w[rspec1 rspec2]
5
- major, minor, revision = RUBY_VERSION.split(".").map{|str| str.to_i }
6
-
7
- in_environment = lambda do |environment, command|
8
- sh %Q{export BUNDLE_GEMFILE="gemfiles/#{environment}/Gemfile"; bundle update && bundle exec #{command}}
9
- end
4
+ task :default => :spec
10
5
 
11
- in_all_environments = lambda do |command|
12
- environments.each do |environment|
13
- puts "\n---#{environment}---\n"
14
- in_environment.call(environment, command)
15
- end
6
+ def bundle_exec(command)
7
+ sh %Q{bundle update && bundle exec #{command}}
16
8
  end
17
9
 
18
- autotest_styles = {
19
- :rspec1 => 'rspec',
20
- :rspec2 => 'rspec2'
21
- }
22
-
23
- desc "Run all specs against Rspec 1 and 2"
10
+ desc "Run all specs"
24
11
  task "spec" do
25
- in_environment.call('rspec1', 'spec spec') if major == 1 && minor < 9
26
- in_environment.call('rspec2', 'rspec spec')
27
- end
28
-
29
- namespace "autotest" do
30
- environments.each do |environment|
31
- desc "Run autotest in #{environment}"
32
- task environment do
33
- in_environment.call(environment, "autotest -s #{autotest_styles[environment.to_sym]}")
34
- end
35
- end
12
+ bundle_exec("rspec spec")
36
13
  end
37
14
 
38
15
  namespace "doc" do
@@ -1,12 +1,15 @@
1
- require "with_model/dsl"
2
-
3
1
  module WithModel
2
+ autoload :Base, "with_model/base"
3
+ autoload :Dsl, "with_model/dsl"
4
+ autoload :VERSION, "with_model/version"
5
+
4
6
  def with_model(name, &block)
5
7
  Dsl.new(name, self).tap { |dsl| dsl.instance_eval(&block) }.execute
6
8
  end
7
9
 
8
10
  def with_table(name, options = {}, &block)
9
11
  connection = ActiveRecord::Base.connection
12
+
10
13
  before do
11
14
  connection.drop_table(name) if connection.table_exists?(name)
12
15
  connection.create_table(name, options, &block)
@@ -1,8 +1,3 @@
1
- begin
2
- require 'mixico'
3
- rescue LoadError
4
- end
5
-
6
1
  module WithModel
7
2
  class Base < ActiveRecord::Base
8
3
  self.abstract_class = true
@@ -10,24 +5,6 @@ module WithModel
10
5
  def with_model?
11
6
  true
12
7
  end
13
-
14
- if defined?(Mixico)
15
- def include(*args)
16
- @modules_to_unmix ||= []
17
- args.each do |mod|
18
- unless @modules_to_unmix.include?(mod)
19
- @modules_to_unmix << mod
20
- end
21
- end
22
- super
23
- end
24
-
25
- def _with_model_deconstructor
26
- @modules_to_unmix.each do |mod|
27
- disable_mixin mod
28
- end if defined?(@modules_to_unmix)
29
- end
30
- end
31
8
  end
32
9
  end
33
10
  end
@@ -1,4 +1,3 @@
1
- require 'with_model/base'
2
1
  require 'active_support/inflector'
3
2
 
4
3
  module WithModel
@@ -24,20 +23,17 @@ module WithModel
24
23
 
25
24
  def execute
26
25
  model_initialization = @model_initialization
27
- const_name = @name.to_s.camelize.to_sym
26
+ const_name = @name.to_s.camelize
28
27
  table_name = "with_model_#{@name.to_s.tableize}_#{$$}"
29
28
 
30
- original_const_defined = Object.const_defined?(const_name)
31
- original_const_value = Object.const_get(const_name) if original_const_defined
32
-
33
29
  model = nil
34
30
 
35
31
  @example_group.with_table(table_name, @table_options, &@table_block)
36
32
 
37
33
  @example_group.before do
38
34
  model = Class.new(WithModel::Base)
39
- silence_warnings { Object.const_set(const_name, model) }
40
- Object.const_get(const_name).class_eval do
35
+ stub_const(const_name, model)
36
+ model.class_eval do
41
37
  self.table_name = table_name
42
38
  self.class_eval(&model_initialization)
43
39
  end
@@ -45,9 +41,6 @@ module WithModel
45
41
  end
46
42
 
47
43
  @example_group.after do
48
- model._with_model_deconstructor if model.respond_to?(:_with_model_deconstructor)
49
- Object.send(:remove_const, const_name)
50
- Object.const_set(const_name, original_const_value) if original_const_defined
51
44
  if defined?(ActiveSupport::Dependencies::Reference)
52
45
  ActiveSupport::Dependencies::Reference.clear!
53
46
  end
@@ -1,3 +1,3 @@
1
1
  module WithModel
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3"
3
3
  end
@@ -79,7 +79,6 @@ describe "ActiveRecord behaviors" do
79
79
  with_table :animals
80
80
 
81
81
  with_model :StuffedAnimal do
82
- table
83
82
  model do
84
83
  has_many :tea_cups, :as => :pet
85
84
  end
@@ -1,16 +1,8 @@
1
1
  require "active_record"
2
2
  require "with_model"
3
3
 
4
- if defined?(RSpec)
5
- # For RSpec 2 users.
6
- RSpec.configure do |config|
7
- config.extend WithModel
8
- end
9
- else
10
- # For RSpec 1 users.
11
- Spec::Runner.configure do |config|
12
- config.extend WithModel
13
- end
4
+ RSpec.configure do |config|
5
+ config.extend WithModel
14
6
  end
15
7
 
16
8
  jruby = RUBY_PLATFORM =~ /\bjava\b/
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Case Commons, LLC", "Grant Hutchins"]
10
10
  s.email = ["casecommons-dev@googlegroups.com", "gems@nertzy.com"]
11
11
  s.homepage = "https://github.com/Casecommons/with_model"
12
- s.summary = %q{Dynamically build a model within an Rspec context}
12
+ s.summary = %q{Dynamically build a model within an RSpec context}
13
13
  s.description = s.summary
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_dependency 'activerecord', '>=2.3.5', '<4.0.0'
21
- s.add_dependency 'rspec', "<3"
21
+ s.add_dependency 'rspec', "~>2.11"
22
22
  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.2.6
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-02 00:00:00.000000000 Z
13
+ date: 2012-08-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &70199881019880 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -25,19 +25,32 @@ dependencies:
25
25
  version: 4.0.0
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *70199881019880
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.5
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: 4.0.0
29
37
  - !ruby/object:Gem::Dependency
30
38
  name: rspec
31
- requirement: &70199881019120 !ruby/object:Gem::Requirement
39
+ requirement: !ruby/object:Gem::Requirement
32
40
  none: false
33
41
  requirements:
34
- - - <
42
+ - - ~>
35
43
  - !ruby/object:Gem::Version
36
- version: '3'
44
+ version: '2.11'
37
45
  type: :runtime
38
46
  prerelease: false
39
- version_requirements: *70199881019120
40
- description: Dynamically build a model within an Rspec context
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '2.11'
53
+ description: Dynamically build a model within an RSpec context
41
54
  email:
42
55
  - casecommons-dev@googlegroups.com
43
56
  - gems@nertzy.com
@@ -54,16 +67,12 @@ files:
54
67
  - LICENSE
55
68
  - README.rdoc
56
69
  - Rakefile
57
- - gemfiles/Gemfile.common
58
- - gemfiles/rspec1/Gemfile
59
- - gemfiles/rspec2/Gemfile
60
70
  - lib/with_model.rb
61
71
  - lib/with_model/base.rb
62
72
  - lib/with_model/dsl.rb
63
73
  - lib/with_model/version.rb
64
74
  - spec/active_record_behaviors_spec.rb
65
75
  - spec/readme_spec.rb
66
- - spec/spec.opts
67
76
  - spec/spec_helper.rb
68
77
  - spec/with_model_spec.rb
69
78
  - with_model.gemspec
@@ -87,13 +96,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
96
  version: '0'
88
97
  requirements: []
89
98
  rubyforge_project:
90
- rubygems_version: 1.8.15
99
+ rubygems_version: 1.8.24
91
100
  signing_key:
92
101
  specification_version: 3
93
- summary: Dynamically build a model within an Rspec context
102
+ summary: Dynamically build a model within an RSpec context
94
103
  test_files:
95
104
  - spec/active_record_behaviors_spec.rb
96
105
  - spec/readme_spec.rb
97
- - spec/spec.opts
98
106
  - spec/spec_helper.rb
99
107
  - spec/with_model_spec.rb
@@ -1,7 +0,0 @@
1
- source :rubygems
2
-
3
- gem "rake"
4
- gem "ZenTest" unless ENV["TRAVIS"]
5
- gem "mixico", :platforms => :mri unless RUBY_VERSION >= "1.9.3"
6
- gem "sqlite3", :platforms => :ruby
7
- gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
@@ -1,5 +0,0 @@
1
- filename = File.join(File.dirname(__FILE__), '..', 'Gemfile.common')
2
- eval(File.read(filename), binding, filename, 1)
3
-
4
- gem "rspec", "~>1.0"
5
- gem "activerecord", "~>2.3"
@@ -1,4 +0,0 @@
1
- filename = File.join(File.dirname(__FILE__), '..', 'Gemfile.common')
2
- eval(File.read(filename), binding, filename, 1)
3
-
4
- gemspec :path => File.join(File.dirname(__FILE__), '..', '..')
@@ -1,2 +0,0 @@
1
- --color
2
- --format nested