the_moderator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/lib/the_moderator/model.rb +3 -1
- data/lib/the_moderator/version.rb +1 -1
- data/spec/the_moderator/model_spec.rb +14 -0
- data/the_moderator.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55799be13b867400ecedb7640347f5f00ace2465
|
4
|
+
data.tar.gz: 5db592b670f29749b6c2d405c94976cecf5c8bdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56fc8b648f6f02549c5037dd2481e680234c9c308f465c03321ade6c00298412940cc935c90f8c6dc24fda2b58ebe2784e85df249c410189c9e27c362fdf617e
|
7
|
+
data.tar.gz: decc32e5617fdd3a1bd6266cc3eb97bc63c77800432b0549ecdc2db53b4c1433af18c54c0970781429fbf756670fd58d49461f08bd8ccf76dd6bd7aa71957c96
|
data/README.md
CHANGED
@@ -69,7 +69,3 @@ A `Moderation` instance has 4 methods:
|
|
69
69
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
70
|
4. Push to the branch (`git push origin my-new-feature`)
|
71
71
|
5. Create new Pull Request
|
72
|
-
|
73
|
-
## License
|
74
|
-
|
75
|
-
TheModerator is released under AGPLv3 license. Copyright (c) 2013 La Fourmi Immo
|
data/lib/the_moderator/model.rb
CHANGED
@@ -64,11 +64,12 @@ module TheModerator
|
|
64
64
|
objects = send(assoc)
|
65
65
|
|
66
66
|
if respond_to?("#{assoc}_attributes=")
|
67
|
-
if objects.is_a?(Array)
|
67
|
+
if objects.is_a?(Array) || objects.is_a?(ActiveRecord::Associations::CollectionProxy)
|
68
68
|
data = moderate_has_many_association(objects, moderated_attributes)
|
69
69
|
assoc_fields = data[:data]
|
70
70
|
assoc_fields_display = data[:data_display]
|
71
71
|
else
|
72
|
+
objects.class.send(:include, TheModerator::Model) unless objects.respond_to?(:moderation_data)
|
72
73
|
data = objects.moderation_data(*moderated_attributes)
|
73
74
|
assoc_fields = data[:data].merge(id: objects.id) unless data[:data].empty?
|
74
75
|
assoc_fields_display = data[:data_display] unless data[:data_display].empty?
|
@@ -83,6 +84,7 @@ module TheModerator
|
|
83
84
|
tab = []
|
84
85
|
|
85
86
|
objects.each do |resource|
|
87
|
+
resource.class.send(:include, TheModerator::Model) unless resource.respond_to?(:moderation_data)
|
86
88
|
data = resource.moderation_data(*moderated_attributes)
|
87
89
|
|
88
90
|
assoc_fields[resource.id] = data[:data].merge(id: resource.id) unless data[:data].empty?
|
@@ -26,6 +26,20 @@ describe TheModerator::Model do
|
|
26
26
|
.to include(page_attributes: {name: 'name', id: category.page.id})
|
27
27
|
expect(category.page.name).to be_nil
|
28
28
|
end
|
29
|
+
|
30
|
+
it 'moderates has_many associations' do
|
31
|
+
page = Page.new(name: 'page')
|
32
|
+
page.save
|
33
|
+
link = page.links.create
|
34
|
+
|
35
|
+
page.attributes = {links_attributes: [{id: link.id, name: 'link'}]}
|
36
|
+
page.moderate(links: [:name])
|
37
|
+
|
38
|
+
expect(page.moderations).to have(1).moderation
|
39
|
+
expect(page.moderations.first.data[:attributes])
|
40
|
+
.to include(links_attributes: {link.id => {name: 'link', id: link.id}})
|
41
|
+
expect(link.name).to be_nil
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
describe '#moderated?' do
|
data/the_moderator.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = %q{Moderate fields of a model or its associations}
|
12
12
|
spec.summary = %q{Moderate fields before their insertion in the database by serializing and saving them into a separate 'moderations' table.}
|
13
13
|
spec.homepage = "https://github.com/gdott9/the_moderator"
|
14
|
-
spec.license = "
|
14
|
+
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_moderator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume DOTT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -176,7 +176,7 @@ files:
|
|
176
176
|
- the_moderator.gemspec
|
177
177
|
homepage: https://github.com/gdott9/the_moderator
|
178
178
|
licenses:
|
179
|
-
-
|
179
|
+
- MIT
|
180
180
|
metadata: {}
|
181
181
|
post_install_message:
|
182
182
|
rdoc_options: []
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
196
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.2.2
|
198
198
|
signing_key:
|
199
199
|
specification_version: 4
|
200
200
|
summary: Moderate fields before their insertion in the database by serializing and
|