yeti 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yeti/editor.rb +8 -2
- data/lib/yeti/version.rb +1 -1
- data/spec/yeti/editor_spec.rb +9 -0
- metadata +3 -3
data/lib/yeti/editor.rb
CHANGED
@@ -57,8 +57,10 @@ module Yeti
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def save
|
61
|
-
|
60
|
+
def save(opts={})
|
61
|
+
if opts.fetch :validate, true
|
62
|
+
return false unless valid?
|
63
|
+
end
|
62
64
|
persist!
|
63
65
|
@previously_changed = changes
|
64
66
|
changed_attributes.clear
|
@@ -69,6 +71,10 @@ module Yeti
|
|
69
71
|
raise NotImplementedError, "#persist!"
|
70
72
|
end
|
71
73
|
|
74
|
+
def without_error?
|
75
|
+
errors.empty?
|
76
|
+
end
|
77
|
+
|
72
78
|
private
|
73
79
|
|
74
80
|
attr_reader :given_id
|
data/lib/yeti/version.rb
CHANGED
data/spec/yeti/editor_spec.rb
CHANGED
@@ -43,6 +43,10 @@ describe Yeti::Editor do
|
|
43
43
|
it "#save returns false" do
|
44
44
|
subject.save.should be false
|
45
45
|
end
|
46
|
+
it "#save(validate: false) calls persist! then returns true" do
|
47
|
+
subject.should_receive :persist!
|
48
|
+
subject.save(validate: false).should be true
|
49
|
+
end
|
46
50
|
end
|
47
51
|
context "when valid" do
|
48
52
|
it "#save calls persist! then returns true" do
|
@@ -91,6 +95,7 @@ describe Yeti::Editor do
|
|
91
95
|
end
|
92
96
|
context "before validation" do
|
93
97
|
its(:errors){ should be_empty }
|
98
|
+
it{ should be_without_error }
|
94
99
|
end
|
95
100
|
context "after validation" do
|
96
101
|
it "has an error on name" do
|
@@ -98,6 +103,10 @@ describe Yeti::Editor do
|
|
98
103
|
subject.errors[:name].should have(1).item
|
99
104
|
subject.errors[:name].should == ["can't be blank"]
|
100
105
|
end
|
106
|
+
it "is not without_error? anymore" do
|
107
|
+
subject.valid?
|
108
|
+
subject.should_not be_without_error
|
109
|
+
end
|
101
110
|
it "can return untranslated error messages" do
|
102
111
|
editor_class.class_eval do
|
103
112
|
dont_translate_error_messages
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yeti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash: -
|
117
|
+
hash: -532776958543363223
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
120
|
requirements:
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash: -
|
126
|
+
hash: -532776958543363223
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
129
|
rubygems_version: 1.8.24
|