spec_support 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
1
  = SpecSupport
2
2
 
3
+ Depends on ActiveModel (and implictly on ActiveRecord
4
+ for the check_all_columns functioality).
5
+
3
6
  == check_all_columns
4
7
 
5
8
  After building a factory that fills out all the
@@ -67,3 +70,12 @@ in a spec do:
67
70
 
68
71
  URI.unescape(rendered).should have_query_params(
69
72
  "f[key][]", "value+with+spaces")
73
+
74
+ == has_error_key?
75
+
76
+ in a spec do:
77
+
78
+ subject.errors.should have_error_key(:name, :blank)
79
+
80
+ to validate that the "name" attribute violates the presence
81
+ validation (and has exactly _that_ error).
@@ -2,4 +2,5 @@ module SpecSupport
2
2
  require 'spec_support/check_all_columns'
3
3
  require 'spec_support/delete_nil_values'
4
4
  require 'spec_support/query_params'
5
+ require 'spec_support/has_error_key'
5
6
  end
@@ -0,0 +1,11 @@
1
+ require 'active_model'
2
+
3
+ module ActiveModel
4
+ class Errors
5
+
6
+ def has_error_key?(attribute, key, options = {})
7
+ self[attribute].include?(self.generate_message(attribute, key, options))
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module SpecSupport
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe 'has_error_key?' do
5
+
6
+ it "ActiveModel is found" do
7
+ ActiveModel
8
+ end
9
+
10
+ before(:each) do
11
+ class TestOfHasErrorKey
12
+ include ActiveModel::Validations
13
+ validates_presence_of :foo
14
+ attr_accessor :foo
15
+ end
16
+ end
17
+
18
+ after(:each) do
19
+ Object.send(:remove_const, :TestOfHasErrorKey)
20
+ end
21
+
22
+ let(:r) do
23
+ TestOfHasErrorKey.new
24
+ end
25
+
26
+ describe "with error key" do
27
+ it "create new record with active_model works" do
28
+ r # should_not raise_error
29
+ end
30
+
31
+ it "has an errors function" do
32
+ r.errors
33
+ end
34
+
35
+ describe "has_error_key?" do
36
+ it "has the error when validation failed" do
37
+ r.valid?
38
+ r.errors.has_error_key?(:foo, :blank).should be_true
39
+ end
40
+
41
+ it "does not have the error when validation passed" do
42
+ r.foo = "bar"
43
+ r.valid?
44
+ r.errors.has_error_key?(:foo, :blank).should be_false
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spec_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Add useful spec/support functionalities that come back in each project
31
47
  email:
32
48
  - peter@vandenabeele.com
@@ -36,6 +52,7 @@ extra_rdoc_files: []
36
52
  files:
37
53
  - lib/spec_support/check_all_columns.rb
38
54
  - lib/spec_support/delete_nil_values.rb
55
+ - lib/spec_support/has_error_key.rb
39
56
  - lib/spec_support/query_params.rb
40
57
  - lib/spec_support/version.rb
41
58
  - lib/spec_support.rb
@@ -45,6 +62,7 @@ files:
45
62
  - README.rdoc
46
63
  - spec/delete_nil_values_spec.rb
47
64
  - spec/file_spec.rb
65
+ - spec/has_error_key_spec.rb
48
66
  - spec/query_params_spec.rb
49
67
  - spec/spec_helper.rb
50
68
  homepage: http://github.com/petervandenabeele/spec_support
@@ -61,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
79
  version: '0'
62
80
  segments:
63
81
  - 0
64
- hash: 823831580201781195
82
+ hash: -2236291549167765582
65
83
  required_rubygems_version: !ruby/object:Gem::Requirement
66
84
  none: false
67
85
  requirements:
@@ -70,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
88
  version: '0'
71
89
  segments:
72
90
  - 0
73
- hash: 823831580201781195
91
+ hash: -2236291549167765582
74
92
  requirements: []
75
93
  rubyforge_project:
76
94
  rubygems_version: 1.8.25
@@ -80,5 +98,6 @@ summary: spec/support for common cases
80
98
  test_files:
81
99
  - spec/delete_nil_values_spec.rb
82
100
  - spec/file_spec.rb
101
+ - spec/has_error_key_spec.rb
83
102
  - spec/query_params_spec.rb
84
103
  - spec/spec_helper.rb