has_moderated 1.0.rc3 → 1.0.rc4

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.
@@ -256,7 +256,7 @@ describe Task do
256
256
  subtask.title.should eq("Subtask 1")
257
257
  end
258
258
 
259
- it "associates an existing subtask on create 2", :focus => true do
259
+ it "associates an existing subtask on create 2" do
260
260
  Subtask.create! :title => "Subtask 1"
261
261
  Subtask.count.should eq(1)
262
262
  Moderation.count.should eq(0)
@@ -265,11 +265,12 @@ describe Task do
265
265
  task.renamed_subtasks << Subtask.first
266
266
  task.save
267
267
 
268
+ Task.count.should eq(0)
268
269
  Moderation.count.should eq(1)
269
270
  Moderation.last.accept
270
271
  Moderation.count.should eq(0)
271
272
 
272
- Task.first.renamed_subtasks.count.should eq(1)
273
+ Task.last.renamed_subtasks.count.should eq(1)
273
274
  subtask = Task.first.renamed_subtasks.first
274
275
  subtask.title.should eq("Subtask 1")
275
276
  end
@@ -494,8 +495,9 @@ describe Task do
494
495
  end
495
496
 
496
497
  it "moderates an attribute" do
497
- Task.create! :title => "Task 1"
498
+ Task.create! :title => "Task 1", :desc => "Description"
498
499
  Task.first.title.should be_blank
500
+ Task.first.desc.should eq("Description")
499
501
  Moderation.last.accept
500
502
  Task.first.title.should eq("Task 1")
501
503
  Task.first.update_attribute(:title, "Task 2")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_moderated
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.rc3
4
+ version: 1.0.rc4
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -187,8 +187,7 @@ files:
187
187
  - lib/generators/has_moderated/install/templates/migration.rb
188
188
  - lib/generators/has_moderated/install/templates/moderation.rb
189
189
  - lib/generators/USAGE
190
- - lib/has_moderated/adapters/active_record.rb
191
- - lib/has_moderated/adapters/proxy.rb
190
+ - lib/has_moderated/active_record/active_record_helpers.rb
192
191
  - lib/has_moderated/associations/base.rb
193
192
  - lib/has_moderated/associations/collection.rb
194
193
  - lib/has_moderated/associations/has_one.rb
@@ -265,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
264
  version: '0'
266
265
  segments:
267
266
  - 0
268
- hash: -754626760659402804
267
+ hash: 1531856163626643736
269
268
  required_rubygems_version: !ruby/object:Gem::Requirement
270
269
  none: false
271
270
  requirements:
@@ -1,109 +0,0 @@
1
- # everything that does with activerecord should be here.
2
- # use a wrapper that calls stuff from here, so that impl. can be switched eg with mongomapper
3
- # also write test that if one attr is moderated and one is not, the unmoderated one must still save immediately!
4
-
5
- module HasModerated
6
- module Adapters
7
- module ActiveRecord
8
- # AR specific
9
- def self.foreign_key(reflection)
10
- if reflection.respond_to?(:foreign_key)
11
- reflection.foreign_key
12
- else # Rails < v3.1
13
- reflection.primary_key_name
14
- end
15
- end
16
-
17
- # General
18
- def self.add_moderations_association(klass)
19
- klass.class_eval do
20
- has_many :moderations, :as => :moderatable, :dependent => :destroy
21
- end
22
- end
23
-
24
- def self.get_default_moderation_attributes(record)
25
- record.attributes
26
- end
27
-
28
- def self.hashize_association(from_record, assoc_name, m)
29
- # todo
30
- through_assocs = {}
31
- from_record.class.reflections.keys.each do |assoc|
32
- join_model = from_record.class.reflections[assoc.to_sym].options[:through]
33
- if join_model
34
- join_model = join_model.to_sym
35
- through_assocs[join_model] ||= []
36
- through_assocs[join_model].push(assoc)
37
- end
38
- end
39
-
40
- assoc = nil
41
- if m.class == Fixnum
42
- assoc = m
43
- elsif m.kind_of? Hash # already a hash (for has_many :through association)
44
- assoc = m
45
- elsif m.respond_to?(:get_moderation_attributes) && m.new_record?
46
- assoc = m.get_moderation_attributes
47
- elsif m.respond_to?(:get_moderation_attributes)
48
- assoc = m.id
49
- else
50
- raise "don't know how to convert #{m.class} to hash"
51
- end
52
-
53
- if through_assocs[assoc_name.to_sym] # TODO !
54
- assoc[:associations] = get_assocs_for_moderation(:all, m)
55
- end
56
- assoc
57
- end
58
-
59
- def self.get_assocs_for_moderation assocs, from_record = nil
60
- from_record ||= self
61
- return if assocs.blank?
62
-
63
- if assocs == :all
64
- assocs = from_record.class.reflections.keys.reject do |r|
65
- r == :moderations
66
- end
67
- end
68
-
69
- assocs = [assocs] unless assocs.respond_to?("[]")
70
-
71
- # check for through assocs
72
- assocs = assocs.dup
73
- through_assocs = {}
74
- assocs.each do |assoc|
75
- join_model = from_record.class.reflections[assoc.to_sym].options[:through]
76
- if join_model
77
- join_model = join_model.to_sym
78
- through_assocs[join_model] ||= []
79
- through_assocs[join_model].push(assoc)
80
- assocs.push(join_model) unless assocs.include?(join_model)
81
- #assocs.delete(assoc)
82
- end
83
- end
84
-
85
- assoc_attrs = {}
86
- assocs.each do |assoc|
87
- one_assoc = []
88
- assoc_value = from_record.send(assoc)
89
- # if it's has_one it won't be an array
90
- assoc_value = [assoc_value] if assoc_value && assoc_value.class != Array
91
- assoc_value ||= []
92
- assoc_value.each do |m|
93
- if m.new_record?
94
- one_assoc.push(m.get_moderation_attributes)
95
- else
96
- one_assoc.push(m.id)
97
- end
98
- if through_assocs[assoc.to_sym]
99
- one_assoc.last[:associations] = get_assocs_for_moderation(:all, m)
100
- end
101
- end
102
- assoc_attrs[assoc] = one_assoc unless one_assoc.empty?
103
- end
104
-
105
- assoc_attrs
106
- end
107
- end
108
- end
109
- end
@@ -1,23 +0,0 @@
1
- module HasModerated
2
- module Adapters
3
- module Proxy
4
- def self.add_moderations_association(klass)
5
- if klass.superclass.to_s == "ActiveRecord::Base"
6
- Adapters::ActiveRecord::add_moderations_association(klass)
7
- end
8
- end
9
-
10
- def self.get_default_moderation_attributes(record)
11
- if record.class.superclass.to_s == "ActiveRecord::Base"
12
- Adapters::ActiveRecord::get_default_moderation_attributes(record)
13
- end
14
- end
15
-
16
- def self.hashize_association(record, assoc_name, m)
17
- if record.class.superclass.to_s == "ActiveRecord::Base"
18
- Adapters::ActiveRecord::hashize_association(record, assoc_name, m)
19
- end
20
- end
21
- end
22
- end
23
- end