activerecord-draft_records 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/active_record/draft_records.rb +13 -0
- data/spec/features_spec.rb +26 -1
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -38,6 +38,19 @@ module ActiveRecord
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# Save the record and, if it is a draft, attempt to transform it in a normal (non-draft) record.
|
42
|
+
def save_and_attempt_to_undraft
|
43
|
+
self.draft, is_draft = false, self.draft
|
44
|
+
|
45
|
+
if self.valid?
|
46
|
+
save
|
47
|
+
elsif self.draft = is_draft
|
48
|
+
save(false)
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
41
54
|
# Save the record as a draft, setting the record attribute 'draft' to true
|
42
55
|
# and saving the record ignoring the validations.
|
43
56
|
def save_as_draft
|
data/spec/features_spec.rb
CHANGED
@@ -44,5 +44,30 @@ describe "Integration features" do
|
|
44
44
|
it "should provide a version of ActiveRecord::Base#find that will look for drafts" do
|
45
45
|
user = User.create_as_draft :email => 'joe@example.com'
|
46
46
|
User.find_drafts(:all).should include(user)
|
47
|
-
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should save a record and attempt to transform into a non-draft" do
|
50
|
+
user = User.create_as_draft :email => 'joe@example.com'
|
51
|
+
user.username = 'joe'
|
52
|
+
user.save_and_attempt_to_undraft.should be(true)
|
53
|
+
user.should_not be_draft
|
54
|
+
user.should_not be_changed
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should save a record and attempt to transform into a non-draft but fail if validation fails" do
|
58
|
+
user = User.create_as_draft :email => 'joe@example.com'
|
59
|
+
user.age = 18
|
60
|
+
user.save_and_attempt_to_undraft.should be(true)
|
61
|
+
user.should be_draft
|
62
|
+
user.should_not be_changed
|
63
|
+
user.age.should == 18
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not transform a normal record in draft when calling save_and_attempt_to_undraft" do
|
67
|
+
user = User.create :email => 'joe@example.com', :username => 'joe'
|
68
|
+
user.username = nil
|
69
|
+
user.save_and_attempt_to_undraft.should be(false)
|
70
|
+
user.should_not be_draft
|
71
|
+
user.should be_changed
|
72
|
+
end
|
48
73
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
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-06-07 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|