accept_values_for 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ h3 0.4.2
2
+
3
+ * Make suitable to use with any ORM based on ActiveModel::Validations
4
+
1
5
  h3. 0.4.0
2
6
 
3
7
  * Migrated to ActiveRecord 3.0
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
1
  source :gemcutter
2
- gem 'activerecord', '>=3.0.0'
2
+ gem 'activemodel', '>=3.0.0'
3
3
  gem "rspec", ">=0"
4
4
 
5
5
  group :development do
6
+ gem "activerecord", ">=3.0.0"
7
+ gem "rspec-rails", ">=2.0.0"
6
8
  gem 'jeweler'
7
9
  gem 'sqlite3-ruby'
8
10
  end
@@ -1,6 +1,17 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ abstract (1.0.0)
5
+ actionpack (3.0.3)
6
+ activemodel (= 3.0.3)
7
+ activesupport (= 3.0.3)
8
+ builder (~> 2.1.2)
9
+ erubis (~> 2.6.6)
10
+ i18n (~> 0.4)
11
+ rack (~> 1.2.1)
12
+ rack-mount (~> 0.6.13)
13
+ rack-test (~> 0.5.6)
14
+ tzinfo (~> 0.3.23)
4
15
  activemodel (3.0.3)
5
16
  activesupport (= 3.0.3)
6
17
  builder (~> 2.1.2)
@@ -14,12 +25,24 @@ GEM
14
25
  arel (2.0.7)
15
26
  builder (2.1.2)
16
27
  diff-lcs (1.1.2)
28
+ erubis (2.6.6)
29
+ abstract (>= 1.0.0)
17
30
  git (1.2.5)
18
31
  i18n (0.5.0)
19
32
  jeweler (1.5.2)
20
33
  bundler (~> 1.0.0)
21
34
  git (>= 1.2.5)
22
35
  rake
36
+ rack (1.2.1)
37
+ rack-mount (0.6.13)
38
+ rack (>= 1.0.0)
39
+ rack-test (0.5.7)
40
+ rack (>= 1.0)
41
+ railties (3.0.3)
42
+ actionpack (= 3.0.3)
43
+ activesupport (= 3.0.3)
44
+ rake (>= 0.8.7)
45
+ thor (~> 0.14.4)
23
46
  rake (0.8.7)
24
47
  rspec (2.4.0)
25
48
  rspec-core (~> 2.4.0)
@@ -29,16 +52,24 @@ GEM
29
52
  rspec-expectations (2.4.0)
30
53
  diff-lcs (~> 1.1.2)
31
54
  rspec-mocks (2.4.0)
55
+ rspec-rails (2.4.1)
56
+ actionpack (~> 3.0)
57
+ activesupport (~> 3.0)
58
+ railties (~> 3.0)
59
+ rspec (~> 2.4.0)
32
60
  sqlite3 (1.3.3)
33
61
  sqlite3-ruby (1.3.3)
34
62
  sqlite3 (>= 1.3.3)
63
+ thor (0.14.6)
35
64
  tzinfo (0.3.24)
36
65
 
37
66
  PLATFORMS
38
67
  ruby
39
68
 
40
69
  DEPENDENCIES
70
+ activemodel (>= 3.0.0)
41
71
  activerecord (>= 3.0.0)
42
72
  jeweler
43
73
  rspec
74
+ rspec-rails (>= 2.0.0)
44
75
  sqlite3-ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{accept_values_for}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-02-25}
12
+ s.date = %q{2011-03-16}
13
13
  s.description = %q{Rspec: When you have a complex validation(e.g. regexp or custom method) on ActiveRecord model
14
14
  you have to write annoying easy specs on which values should be accepted by your validation method and which should not.
15
15
  accepts_values_for rspec matcher simplify the code. See example for more information.
@@ -36,10 +36,7 @@ accepts_values_for rspec matcher simplify the code. See example for more informa
36
36
  s.test_files = [
37
37
  "spec/accept_values_for_spec.rb",
38
38
  "spec/discover_spec.rb",
39
- "spec/spec_helper.rb",
40
- "test/lib/test.rb",
41
- "test/test/helper.rb",
42
- "test/test/test_test.rb"
39
+ "spec/spec_helper.rb"
43
40
  ]
44
41
 
45
42
  if s.respond_to? :specification_version then
@@ -47,19 +44,25 @@ accepts_values_for rspec matcher simplify the code. See example for more informa
47
44
  s.specification_version = 3
48
45
 
49
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
47
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0"])
51
48
  s.add_runtime_dependency(%q<rspec>, [">= 0"])
49
+ s.add_development_dependency(%q<activerecord>, [">= 3.0.0"])
50
+ s.add_development_dependency(%q<rspec-rails>, [">= 2.0.0"])
52
51
  s.add_development_dependency(%q<jeweler>, [">= 0"])
53
52
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
54
53
  else
55
- s.add_dependency(%q<activerecord>, [">= 3.0.0"])
54
+ s.add_dependency(%q<activemodel>, [">= 3.0.0"])
56
55
  s.add_dependency(%q<rspec>, [">= 0"])
56
+ s.add_dependency(%q<activerecord>, [">= 3.0.0"])
57
+ s.add_dependency(%q<rspec-rails>, [">= 2.0.0"])
57
58
  s.add_dependency(%q<jeweler>, [">= 0"])
58
59
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
59
60
  end
60
61
  else
61
- s.add_dependency(%q<activerecord>, [">= 3.0.0"])
62
+ s.add_dependency(%q<activemodel>, [">= 3.0.0"])
62
63
  s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<activerecord>, [">= 3.0.0"])
65
+ s.add_dependency(%q<rspec-rails>, [">= 2.0.0"])
63
66
  s.add_dependency(%q<jeweler>, [">= 0"])
64
67
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
65
68
  end
@@ -1,4 +1,4 @@
1
- if defined?(ActiveRecord)
1
+ if defined?(ActiveModel)
2
2
 
3
3
  # In order to spec a complex validation for ActiveRecord models
4
4
  # Implemented accept_values_for custom matcher
@@ -23,6 +23,7 @@ if defined?(ActiveRecord)
23
23
  AcceptValuesFor.new(attribute, *values)
24
24
  end
25
25
 
26
+
26
27
  end
27
28
 
28
29
  class AcceptValuesFor #:nodoc:
@@ -30,11 +31,12 @@ class AcceptValuesFor #:nodoc:
30
31
  def initialize(attribute, *values)
31
32
  @attribute = attribute
32
33
  @values = values
34
+
33
35
  end
34
36
 
35
37
  def matches?(model)
36
38
  @model = model
37
- return false unless model.is_a?(ActiveRecord::Base)
39
+ return false unless model.class.included_modules.include?(ActiveModel::Validations)
38
40
  @values.each do |value|
39
41
  model.send("#{@attribute}=", value)
40
42
  model.valid?
@@ -48,7 +50,7 @@ class AcceptValuesFor #:nodoc:
48
50
 
49
51
  def does_not_match?(model)
50
52
  @model = model
51
- return false unless model.is_a?(ActiveRecord::Base)
53
+ return false unless model.class.included_modules.include?(ActiveModel::Validations)
52
54
  @values.each do |value|
53
55
  model.send("#{@attribute}=", value)
54
56
  model.valid?
@@ -62,9 +64,8 @@ class AcceptValuesFor #:nodoc:
62
64
 
63
65
  def failure_message_for_should
64
66
  result = "expected #{@model.inspect} to accept value #{@failed_value.inspect} for #{@attribute.inspect}, but it was not\n"
65
- if @model.respond_to?(:errors) && ActiveModel::Errors === @model.errors
66
- result += "Errors: " + @model.errors[(@attribute)].to_a.
67
- map{|a| "#{@attribute} #{a}"}.join(", ")
67
+ if @model.respond_to?(:errors) && @model.errors.is_a?(ActiveModel::Errors)
68
+ result += "Errors: #{@attribute} " + Array(@model.errors[@attribute]).join(", ")
68
69
  end
69
70
  result
70
71
  end
@@ -77,6 +78,5 @@ class AcceptValuesFor #:nodoc:
77
78
  "accept values #{@values.map(&:inspect).join(', ')} for #{@attribute.inspect} attribute"
78
79
  end
79
80
 
80
-
81
81
  end
82
82
 
@@ -56,8 +56,10 @@ describe "Discover" do
56
56
  it { should discover(java) }
57
57
 
58
58
  it { should discover(json, java, jruby) }
59
- it { should discover(java, jruby, json).with_exact_order }
59
+
60
+ it { should discover(java, jruby, json).with_exact_order}
60
61
  it { should discover(java, json).with_exact_order }
62
+
61
63
 
62
64
  it { should_not discover(ruby) }
63
65
  it { should_not discover(ruby, python) }
@@ -5,9 +5,15 @@ require 'active_record'
5
5
  require 'lib/accept_values_for'
6
6
  require 'lib/discover'
7
7
 
8
+ require "rspec/rails/adapters"
9
+ require "rspec/rails/fixture_support"
10
+
8
11
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
12
  ActiveRecord::Base.configurations = true
10
13
 
14
+ File.open('spec.log', "w").close
15
+ ActiveRecord::Base.logger = Logger.new('spec.log')
16
+
11
17
  ActiveRecord::Schema.verbose = false
12
18
  ActiveRecord::Schema.define(:version => 1) do
13
19
 
@@ -23,6 +29,7 @@ ActiveRecord::Schema.define(:version => 1) do
23
29
  end
24
30
 
25
31
  RSpec.configure do |config|
32
+ config.use_transactional_examples = true
26
33
  config.before(:each) do
27
34
  class ::Group < ActiveRecord::Base
28
35
  has_many :people
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accept_values_for
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev
@@ -15,12 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-25 00:00:00 +02:00
18
+ date: 2011-03-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ name: activemodel
23
+ type: :runtime
22
24
  prerelease: false
23
- name: activerecord
24
25
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
@@ -33,10 +34,10 @@ dependencies:
33
34
  - 0
34
35
  version: 3.0.0
35
36
  requirement: *id001
36
- type: :runtime
37
37
  - !ruby/object:Gem::Dependency
38
- prerelease: false
39
38
  name: rspec
39
+ type: :runtime
40
+ prerelease: false
40
41
  version_requirements: &id002 !ruby/object:Gem::Requirement
41
42
  none: false
42
43
  requirements:
@@ -47,25 +48,43 @@ dependencies:
47
48
  - 0
48
49
  version: "0"
49
50
  requirement: *id002
50
- type: :runtime
51
51
  - !ruby/object:Gem::Dependency
52
+ name: activerecord
53
+ type: :development
52
54
  prerelease: false
53
- name: jeweler
54
55
  version_requirements: &id003 !ruby/object:Gem::Requirement
55
56
  none: false
56
57
  requirements:
57
58
  - - ">="
58
59
  - !ruby/object:Gem::Version
59
- hash: 3
60
+ hash: 7
60
61
  segments:
62
+ - 3
61
63
  - 0
62
- version: "0"
64
+ - 0
65
+ version: 3.0.0
63
66
  requirement: *id003
64
- type: :development
65
67
  - !ruby/object:Gem::Dependency
68
+ name: rspec-rails
69
+ type: :development
66
70
  prerelease: false
67
- name: sqlite3-ruby
68
71
  version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 15
77
+ segments:
78
+ - 2
79
+ - 0
80
+ - 0
81
+ version: 2.0.0
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
69
88
  none: false
70
89
  requirements:
71
90
  - - ">="
@@ -74,8 +93,21 @@ dependencies:
74
93
  segments:
75
94
  - 0
76
95
  version: "0"
77
- requirement: *id004
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3-ruby
78
99
  type: :development
100
+ prerelease: false
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirement: *id006
79
111
  description: |
80
112
  Rspec: When you have a complex validation(e.g. regexp or custom method) on ActiveRecord model
81
113
  you have to write annoying easy specs on which values should be accepted by your validation method and which should not.