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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 421b8e05b09df91ed6b0563933587edf3f07e5b4
4
- data.tar.gz: 203d3f693d580c47b1868dd435eaf3247d0c11e5
3
+ metadata.gz: 55799be13b867400ecedb7640347f5f00ace2465
4
+ data.tar.gz: 5db592b670f29749b6c2d405c94976cecf5c8bdb
5
5
  SHA512:
6
- metadata.gz: f70f543eab96bce0a9449022f5e21a99bed5da5146e8fd6c5888989e03082e2cde39792f5827de4f6b7e21260aa910e33b88d81e0ad9f165337ea765f68a07cb
7
- data.tar.gz: db57bac199438ac4f4f6b77144b7fed879de8975023492ab3d0c8ee8fda49c0e326fef62d3d82eee6e594f6d3e2f5988e42e3253a9caec62830270d04b69a925
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
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module TheModerator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
@@ -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 = "AGPL"
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.0
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-08-27 00:00:00.000000000 Z
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
- - AGPL
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.4.1
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