has_moderated 1.0.beta → 1.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -79,6 +79,7 @@ Be especially careful if you are moderating a has_many :through association. In
79
79
  has_moderated_association :bookshelves, :books
80
80
 
81
81
  == Manage moderations
82
+
82
83
  To see pending moderations, simply call
83
84
 
84
85
  Moderation.all
@@ -106,6 +107,18 @@ to discard (destroy) it, call
106
107
 
107
108
  Do not use moderation.destroy, because discard triggers certain callbacks which may be necessary.
108
109
 
110
+ == Preview moderation
111
+
112
+ You can see a preview of what a moderation will do. Right now, you can only preview changes to attributes, not associations. To create a preview of how a record will look after applying a moderation, use
113
+
114
+ record_preview = moderation.preview
115
+
116
+ This will return the record with modified attributes, but not saved to database. You can see what changed by looking at (provided by ActiveRecord)
117
+
118
+ record_preview.changes
119
+
120
+ Just be careful not to call record_preview.save, as this will create a new moderation record.
121
+
109
122
  == Bypassing moderation
110
123
  To bypass moderation (e.g. for admin users), wrap your code into without_moderation like so:
111
124
 
@@ -51,7 +51,7 @@ module HasModerated
51
51
  end
52
52
 
53
53
  module ApplyModeration
54
- def self.apply(moderation, value)
54
+ def self.apply(moderation, value, do_save = true)
55
55
  if value[:attributes].present?
56
56
  rec = moderation.moderatable
57
57
  rec.without_moderation do
@@ -59,9 +59,11 @@ module HasModerated
59
59
  # bypass attr_accessible protection
60
60
  rec.send(attr_name.to_s+"=", attr_value)
61
61
  end
62
- rec.save(:validate => false) # don't run validations
62
+ # don't run validations on save (were already ran when moderation was created)
63
+ rec.save(:validate => false) if do_save
63
64
  end
64
65
  end
66
+ rec
65
67
  end
66
68
  end
67
69
 
@@ -20,5 +20,9 @@ module HasModerated
20
20
  end
21
21
  self.destroy
22
22
  end
23
+
24
+ def preview
25
+ HasModerated::ModeratedAttributes::ApplyModeration::apply(self, parsed_data, false)
26
+ end
23
27
  end
24
28
  end
@@ -1,3 +1,3 @@
1
1
  module HasModerated
2
- VERSION = "1.0.beta"
2
+ VERSION = "1.0.beta2"
3
3
  end
@@ -7528,3 +7528,16 @@ Migrating to CreatePhotos (20120520215224)
7528
7528
   (0.0ms) PRAGMA index_list("task_photos")
7529
7529
   (0.0ms) PRAGMA index_list("tasks")
7530
7530
   (0.0ms) PRAGMA index_list("tasks_jointable")
7531
+ DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future releases,simply use Ruby memoization pattern instead. (called from /Users/apple/rails/has_moderated/test/dummy/config/environment.rb:5)
7532
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
7533
+ Migrating to InitialSchema (20120520215008)
7534
+ Migrating to CreatePhotos (20120520215224)
7535
+  (0.1ms) select sqlite_version(*)
7536
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
7537
+  (0.0ms) PRAGMA index_list("moderations")
7538
+  (0.0ms) PRAGMA index_list("photos")
7539
+  (0.0ms) PRAGMA index_list("subtasks")
7540
+  (0.0ms) PRAGMA index_list("task_connections")
7541
+  (0.0ms) PRAGMA index_list("task_photos")
7542
+  (0.0ms) PRAGMA index_list("tasks")
7543
+  (0.0ms) PRAGMA index_list("tasks_jointable")