activerecord-draft_records 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/active_record/draft_records.rb +11 -6
- data/spec/features_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -38,16 +38,21 @@ module ActiveRecord
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# Override valid? to automatically and temporarily set it as a draft for the validation.
|
42
|
+
def valid?
|
43
|
+
self.draft, is_draft = false, self.draft
|
44
|
+
super
|
45
|
+
ensure
|
46
|
+
self.draft = is_draft
|
47
|
+
end
|
48
|
+
|
41
49
|
# Save the record and, if it is a draft, attempt to transform it in a normal (non-draft) record.
|
42
50
|
def save_and_attempt_to_undraft
|
43
|
-
|
44
|
-
|
45
|
-
if self.valid?
|
46
|
-
save
|
47
|
-
elsif self.draft = is_draft
|
51
|
+
if self.draft?
|
52
|
+
self.draft = false if self.valid?
|
48
53
|
save(false)
|
49
54
|
else
|
50
|
-
|
55
|
+
save
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
data/spec/features_spec.rb
CHANGED
@@ -70,4 +70,13 @@ describe "Integration features" do
|
|
70
70
|
user.should_not be_draft
|
71
71
|
user.should be_changed
|
72
72
|
end
|
73
|
+
|
74
|
+
it "should validate object as not draft" do
|
75
|
+
User.create :email => 'joe@example.com', :username => 'joe'
|
76
|
+
user = User.new :username => 'joe'
|
77
|
+
user.save_as_draft.should be_true
|
78
|
+
user.should_not be_valid
|
79
|
+
user.errors.on(:username).should_not be_blank
|
80
|
+
user.errors.on(:username).should include("has already been taken")
|
81
|
+
end
|
73
82
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Rodrigo Kochenburger
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-29 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|