review_and_approve 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -35,7 +35,10 @@ end
35
35
 
36
36
  To mark existing data as published:
37
37
 
38
- $ bundle exec rake review_and_approve:create_caches
38
+ $ bundle exec rake review_and_approve:create_caches
39
+ # => Marks all records of all classes using review_and_approve as published
40
+ $ bundle exec rake review_and_approve:create_caches[Product, AnotherClass]
41
+ # => Only mark the records for listed classes
39
42
 
40
43
  Use Cancan or other authorization mechanism to define a custom ability to 'publish' the records
41
44
  Make sure your controller has access to current_ability method and it returns true or false on can? :publish, @product
@@ -74,9 +77,9 @@ A method called `published_version` is defined on the model that provides access
74
77
  check out delta.css in the gem and override the styles in your application
75
78
  ```
76
79
 
77
- ## Limitations
80
+ ## Limitations and Warnings
78
81
  * only certified on Rails 3.1, ruby 1.9.2
79
- * Currently depends on the application to call attr_accessible
82
+ * Currently depends on the application to set up attr_accessible properly, else all mass-assignment would be disabled (You *should* have attr_accessible set up on rails 3.x anyway)
80
83
 
81
84
 
82
85
  ## Contributing
@@ -84,5 +87,6 @@ A method called `published_version` is defined on the model that provides access
84
87
  1. Fork it
85
88
  2. Create your feature branch (`git checkout -b my-new-feature`)
86
89
  3. Commit your changes (`git commit -am 'Add some feature'`)
87
- 4. Push to the branch (`git push origin my-new-feature`)
88
- 5. Create new Pull Request
90
+ 4. Run all tests to confirm they pass (`bundle exec rake`)
91
+ 5. Push to the branch (`git push origin my-new-feature`)
92
+ 6. Create new Pull Request
@@ -10,15 +10,20 @@
10
10
  <th scope="col" class="rounded-q4">Current Value</th>
11
11
  </tr>
12
12
  </thead>
13
- <% diff_keys.each do |key| %>
13
+
14
14
  <tbody>
15
- <tr>
16
- <td><%= key %></td>
17
- <td><%= published[key] || "<BLANK>" %></td>
18
- <td><%= current[key] || "<BLANK>" %></td>
19
- </tr>
15
+ <% diff_keys.each do |key| %>
16
+ <tr>
17
+ <td><%= key rescue "" %></td>
18
+ <%# if !published.is_a? Hash and !published.is_a? Array %>
19
+ <td><%= published || "<BLANK>" %></td>
20
+ <td><%= current || "<BLANK>" %></td>
21
+ <%# end %>
22
+ </tr>
23
+ <%#= render :partial => 'review_and_approve/line_item', :locals => {:published => published[key], :current => current[key], :key => key, :depth => 0} %>
24
+ <% end %>
20
25
  </tbody>
21
- <% end %>
26
+
22
27
  </table>
23
28
  <% else %>
24
29
  Latest version is published
@@ -0,0 +1,30 @@
1
+ <% puts "in line item with" %>
2
+ <% puts "published:#{published rescue ""}" %>
3
+ <% puts "current:#{current rescue ""}" %>
4
+ <% puts "key:#{key rescue ""}" %>
5
+ <% current ||= {} %>
6
+ <tr>
7
+ <% (0..depth).each do %>
8
+ <td></td>
9
+ <% end %>
10
+ <td><%= key rescue "" %></td>
11
+ <% if !published.is_a? Hash and !published.is_a? Array %>
12
+ <td><%= published || "<BLANK>" %></td>
13
+ <td><%= current || "<BLANK>" %></td>
14
+ <% end %>
15
+ </tr>
16
+ <% if published.is_a? Array %>
17
+ <% published.each do |item| %>
18
+ <% if current. %>
19
+ <% pub = (published.include? item) ? item : nil %>
20
+ <% cur = (current.include? item) ? item : nil %>
21
+ <%= render :partial => 'review_and_approve/line_item',
22
+ :locals => {:depth => depth+1, :published => pub, :current => cur} %>
23
+ <% end %>
24
+ <% end %>
25
+ <% end %>
26
+ <% if published.is_a? Hash %>
27
+ <% published.diff(current).keys.each do |key| %>
28
+ <%= render :partial => 'review_and_approve/line_item', :locals => {:published => published[key], :current => current[key], :key => key, :depth => depth+1} %>
29
+ <% end %>
30
+ <% end %>
@@ -34,12 +34,12 @@ module ReviewAndApprove
34
34
  send(:define_method, :review_and_approve_after_save_callback) do |publish = false|
35
35
  published = self.send(field) || publish
36
36
  #If we are publishing the record
37
- if published and (published==true or published=="true" or self.send(field).to_i>0 rescue false) #in case the field gets set to "0" and "1"
37
+ if published and (published==true or published=="true" or published=="on" or self.send(field).to_i>0 rescue false) #in case the field gets set to "0" and "1"
38
38
  methods.each do |method|
39
39
  # Refresh all caches
40
- CacheRecord.find_or_initialize_by_key(key_proc.call(self, method)).tap do |cr|
41
- cr.cache_data = self.send(method)
42
- end.save
40
+ cr = CacheRecord.find_or_initialize_by_key(key_proc.call(self, method))
41
+ cr.cache_data = self.send(method)
42
+ cr.save
43
43
  end
44
44
  end
45
45
 
@@ -58,7 +58,7 @@ module ReviewAndApprove
58
58
  validates_each field do |record, attr, value|
59
59
  able = Thread.current[:reviewAndApprove_current_ability].try(:can?, :publish, record)
60
60
  # if user can not publish the record, create an error.
61
- if !able and value and (value==true or value=="true" or value.to_i>0 rescue false)
61
+ if !able and value and (value==true or value=="true" or value=="on" or value.to_i>0 rescue false)
62
62
  record.errors[attr] << "can not be marked as true by this user"
63
63
  end
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module ReviewAndApprove
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,10 +1,18 @@
1
1
  desc 'Create caches for existing data'
2
2
  namespace :review_and_approve do
3
- task :create_caches => :environment do
3
+ task :create_caches, [:arg1, :arg2, :arg3, :arg4, :arg5] => :environment do |t, args|
4
4
  puts "In review_and_approve:create_caches"
5
- ActiveRecord::Base.subclasses.select{|model|
6
- model._using_rev_app? rescue false
7
- }.each do |model|
5
+
6
+ models = []
7
+ if args.count > 0
8
+ models = args.map{|k,v| v.constantize rescue nil}.compact
9
+ else
10
+ models = ActiveRecord::Base.subclasses.select{|model|
11
+ model._using_rev_app? rescue false
12
+ }
13
+ end
14
+
15
+ models.each do |model|
8
16
 
9
17
  puts "Processing #{model.name}"
10
18
  model.find_each do |obj|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: review_and_approve
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paramveer Singh
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-05-20 00:00:00 Z
13
+ date: 2013-05-23 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -113,6 +113,7 @@ files:
113
113
  - app/assets/stylesheets/review_and_approve/application.css
114
114
  - app/assets/stylesheets/review_and_approve/delta.css
115
115
  - app/views/review_and_approve/_delta.html.erb
116
+ - app/views/review_and_approve/_line_item.html.erb
116
117
  - lib/generators/review_and_approve/install/install_generator.rb
117
118
  - lib/generators/review_and_approve/install/templates/create_cache_records.rb
118
119
  - lib/review_and_approve/cache_record.rb