fine_print 2.3.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +101 -61
  3. data/Rakefile +2 -2
  4. data/app/controllers/fine_print/application_controller.rb +5 -5
  5. data/app/controllers/fine_print/contracts_controller.rb +15 -12
  6. data/app/controllers/fine_print/signatures_controller.rb +11 -8
  7. data/app/models/fine_print/contract.rb +10 -10
  8. data/app/models/fine_print/signature.rb +9 -8
  9. data/app/views/fine_print/contracts/_form.html.erb +8 -8
  10. data/app/views/fine_print/contracts/edit.html.erb +2 -2
  11. data/app/views/fine_print/contracts/index.html.erb +39 -16
  12. data/app/views/fine_print/contracts/new.html.erb +3 -1
  13. data/app/views/fine_print/contracts/new_version.html.erb +7 -4
  14. data/app/views/fine_print/contracts/show.html.erb +33 -18
  15. data/app/views/fine_print/signatures/_form.html.erb +7 -4
  16. data/app/views/fine_print/signatures/index.html.erb +17 -9
  17. data/app/views/fine_print/signatures/new.html.erb +6 -4
  18. data/config/initializers/fine_print.rb +39 -36
  19. data/config/routes.rb +3 -2
  20. data/db/migrate/0_install_fine_print.rb +8 -8
  21. data/lib/fine_print.rb +40 -55
  22. data/lib/fine_print/action_controller/base.rb +118 -0
  23. data/lib/fine_print/configuration.rb +24 -0
  24. data/lib/fine_print/engine.rb +10 -6
  25. data/lib/fine_print/version.rb +1 -1
  26. data/lib/tasks/fine_print_tasks.rake +4 -2
  27. data/spec/controllers/contracts_controller_spec.rb +22 -22
  28. data/spec/controllers/home_controller_spec.rb +1 -1
  29. data/spec/controllers/signatures_controller_spec.rb +11 -11
  30. data/spec/dummy/app/views/layouts/application.html.erb +2 -1
  31. data/spec/dummy/config/initializers/fine_print.rb +2 -1
  32. data/spec/dummy/config/routes.rb +0 -1
  33. data/spec/dummy/db/migrate/1_create_dummy_users.rb +1 -1
  34. data/spec/dummy/db/test.sqlite3 +0 -0
  35. data/spec/dummy/log/test.log +585 -3119
  36. data/spec/factories/fine_print/contract.rb +1 -1
  37. data/spec/factories/fine_print/signature.rb +2 -2
  38. data/spec/factories/user.rb +1 -1
  39. data/spec/lib/fine_print/action_controller/base_spec.rb +30 -0
  40. data/spec/lib/fine_print_spec.rb +14 -11
  41. data/spec/models/contract_spec.rb +2 -2
  42. data/spec/models/signature_spec.rb +1 -1
  43. metadata +6 -5
  44. data/lib/fine_print/controller_includes.rb +0 -93
  45. data/spec/lib/fine_print/controller_includes_spec.rb +0 -25
@@ -1,13 +1,13 @@
1
1
  module FinePrint
2
2
  class Signature < ActiveRecord::Base
3
- belongs_to :contract, :inverse_of => :signatures
4
- belongs_to :user, :polymorphic => true
3
+ belongs_to :contract, inverse_of: :signatures
4
+ belongs_to :user, polymorphic: true
5
5
 
6
- validate :contract_published, :on => :create
6
+ validate :contract_published, on: :create
7
7
 
8
- validates :contract, :presence => true
9
- validates :contract_id, :uniqueness => {:scope => [:user_type, :user_id]}
10
- validates :user, :presence => true
8
+ validates :contract, presence: true
9
+ validates :contract_id, uniqueness: { scope: [:user_type, :user_id] }
10
+ validates :user, presence: true
11
11
 
12
12
  default_scope { order(:contract_id, :user_type, :user_id) }
13
13
 
@@ -19,8 +19,9 @@ module FinePrint
19
19
 
20
20
  def contract_published
21
21
  return if contract.is_published?
22
- errors.add(:contract, I18n.t(
23
- 'fine_print.signature.errors.contract.not_published'))
22
+ errors.add(
23
+ :contract, I18n.t('fine_print.signature.errors.contract.not_published')
24
+ )
24
25
  false
25
26
  end
26
27
  end
@@ -1,4 +1,4 @@
1
- <%= form_for(@contract, :html => {:class => 'fine_print'}) do |f| %>
1
+ <%= form_for(@contract, html: { class: 'fine_print' }) do |f| %>
2
2
  <% if @contract.errors.any? %>
3
3
  <div id='error_explanation' class='fine_print errors'>
4
4
  <h4 class='fine_print heading'>
@@ -14,27 +14,27 @@
14
14
  <% end %>
15
15
 
16
16
  <div class='field'>
17
- <%= f.label :name, :class => 'fine_print' %>
18
- <%= f.text_field :name, :size => 40, :class => 'fine_print text_field' %>
17
+ <%= f.label :name, class: 'fine_print' %>
18
+ <%= f.text_field :name, size: 40, class: 'fine_print text_field' %>
19
19
  <div class='fine_print field_description'>
20
20
  <%= t 'fine_print.contract.descriptions.name' %>
21
21
  </div>
22
22
  </div>
23
23
  <div class='field'>
24
- <%= f.label :title, :class => 'fine_print' %>
25
- <%= f.text_field :title, :size => 40, :class => 'fine_print text_field' %>
24
+ <%= f.label :title, class: 'fine_print' %>
25
+ <%= f.text_field :title, size: 40, class: 'fine_print text_field' %>
26
26
  <div class='fine_print field_description'>
27
27
  <%= t 'fine_print.contract.descriptions.title' %>
28
28
  </div>
29
29
  </div>
30
30
  <div class='field'>
31
- <%= f.label :content, :class => 'fine_print' %>
32
- <%= f.text_area :content, :cols => 56, :class => 'fine_print text_area' %>
31
+ <%= f.label :content, class: 'fine_print' %>
32
+ <%= f.text_area :content, cols: 56, class: 'fine_print text_area' %>
33
33
  </div>
34
34
 
35
35
  <br>
36
36
 
37
37
  <div class='actions'>
38
- <%= f.submit nil, :class => 'fine_print submit' %>
38
+ <%= f.submit nil, class: 'fine_print submit' %>
39
39
  </div>
40
40
  <% end %>
@@ -8,8 +8,8 @@
8
8
 
9
9
  <div class='fine_print links'>
10
10
  <%= link_to t('fine_print.contract.actions.show'), @contract,
11
- :class => 'fine_print link' %> |
11
+ class: 'fine_print link' %> |
12
12
  <%= link_to t('fine_print.contract.actions.list'), contracts_path,
13
- :class => 'fine_print link' %>
13
+ class: 'fine_print link' %>
14
14
  </div>
15
15
  </div>
@@ -12,30 +12,53 @@
12
12
 
13
13
  <ul class='fine_print'>
14
14
  <% contracts.each do |contract| %>
15
- <li><%= link_to contract.title, contract, :class => 'fine_print link' %>
16
- (<%= contract.version.nil? ? t('fine_print.contract.status.draft') : \
17
- t('fine_print.contract.status.version', version: contract.version.to_s) %>)
15
+ <li><%= link_to contract.title, contract, class: 'fine_print link' %>
16
+ (<%= contract.version.nil? ? \
17
+ t('fine_print.contract.status.draft') : \
18
+ t('fine_print.contract.status.version',
19
+ version: contract.version.to_s) %>)
18
20
  <% if contract.signatures.empty? %>
19
21
  [<%= link_to t('fine_print.contract.actions.edit'),
20
- edit_contract_path(contract), :class => 'fine_print link' %>]
22
+ edit_contract_path(contract),
23
+ class: 'fine_print link' %>]
21
24
  <% if contract.is_published? %>
22
- [<%= link_to t('fine_print.contract.actions.unpublish'),
23
- unpublish_contract_path(contract), :method => :put,
24
- :data => {:confirm => t('fine_print.contract.actions.confirm.unpublish')}, :class => 'fine_print link' %>]
25
+ [<%= link_to(
26
+ t('fine_print.contract.actions.unpublish'),
27
+ unpublish_contract_path(contract),
28
+ method: :put,
29
+ data: {
30
+ confirm: t('fine_print.contract.actions.confirm.unpublish')
31
+ },
32
+ class: 'fine_print link'
33
+ ) %>]
25
34
  <% else %>
26
- [<%= link_to t('fine_print.contract.actions.publish'),
27
- publish_contract_path(contract), :method => :put,
28
- :data => {:confirm => t('fine_print.contract.actions.confirm.publish')}, :class => 'fine_print link' %>]
35
+ [<%= link_to(
36
+ t('fine_print.contract.actions.publish'),
37
+ publish_contract_path(contract),
38
+ method: :put,
39
+ data: {
40
+ confirm: t('fine_print.contract.actions.confirm.publish')
41
+ },
42
+ class: 'fine_print link'
43
+ ) %>]
29
44
  <% end %>
30
- [<%= link_to t('fine_print.contract.actions.delete'), contract,
31
- :method => :delete, :data => {:confirm => t('fine_print.contract.actions.confirm.delete')}, :class => 'fine_print link' %>]
45
+ [<%= link_to(
46
+ t('fine_print.contract.actions.delete'),
47
+ contract,
48
+ method: :delete,
49
+ data: {
50
+ confirm: t('fine_print.contract.actions.confirm.delete')
51
+ },
52
+ class: 'fine_print link'
53
+ ) %>]
32
54
  <% else %>
33
55
  [<%= link_to t('fine_print.contract.actions.new_version'),
34
- new_version_contract_path(contract), :method => :post,
35
- :class => 'fine_print link' %>]
56
+ new_version_contract_path(contract),
57
+ method: :post,
58
+ class: 'fine_print link' %>]
36
59
  [<%= link_to t('fine_print.contract.actions.signatures'),
37
60
  contract_signatures_path(contract),
38
- :class => 'fine_print link' %>]
61
+ class: 'fine_print link' %>]
39
62
  <% end %>
40
63
  </li>
41
64
  <% end %>
@@ -46,7 +69,7 @@
46
69
  <% end %>
47
70
 
48
71
  <div class='fine_print links'>
49
- <%= link_to 'New Contract', new_contract_path, :class => 'fine_print link' %>
72
+ <%= link_to 'New Contract', new_contract_path, class: 'fine_print link' %>
50
73
  </div>
51
74
 
52
75
  </div>
@@ -6,6 +6,8 @@
6
6
  <br>
7
7
 
8
8
  <div class='fine_print links'>
9
- <%= link_to t('fine_print.contract.actions.list'), contracts_path, :class => 'fine_print link' %>
9
+ <%= link_to t('fine_print.contract.actions.list'),
10
+ contracts_path,
11
+ class: 'fine_print link' %>
10
12
  </div>
11
13
  </div>
@@ -1,5 +1,7 @@
1
- <h1 class='fine_print heading'><%= t('fine_print.contract.actions.new_version_of',
2
- contract: @contract.name) %></h1>
1
+ <h1 class='fine_print heading'>
2
+ <%= t('fine_print.contract.actions.new_version_of',
3
+ contract: @contract.name) %>
4
+ </h1>
3
5
 
4
6
  <div class='fine_print new_contract_version'>
5
7
  <%= render 'form' %>
@@ -7,7 +9,8 @@
7
9
  <br>
8
10
 
9
11
  <div class='fine_print links'>
10
- <%= link_to t('fine_print.contract.actions.list'), contracts_path,
11
- :class => 'fine_print link' %>
12
+ <%= link_to t('fine_print.contract.actions.list'),
13
+ contracts_path,
14
+ class: 'fine_print link' %>
12
15
  </div>
13
16
  </div>
@@ -2,37 +2,52 @@
2
2
 
3
3
  <br>
4
4
 
5
- <h4 class='fine_print heading'><%= t('fine_print.contract.status.name', name: @contract.name) %></h4>
5
+ <h4 class='fine_print heading'><%= t('fine_print.contract.status.name',
6
+ name: @contract.name) %></h4>
6
7
 
7
- <%= render :partial => 'show', :locals => {:contract => @contract} %>
8
+ <%= render partial: 'show', locals: { contract: @contract } %>
8
9
 
9
10
  <br>
10
11
 
11
12
  <div class='fine_print links'>
12
13
  <% if @contract.signatures.empty? %>
13
- <%= link_to t('fine_print.contract.actions.edit'), edit_contract_path(@contract),
14
- :class => 'fine_print link' %> |
14
+ <%= link_to t('fine_print.contract.actions.edit'),
15
+ edit_contract_path(@contract),
16
+ class: 'fine_print link' %> |
15
17
  <% if @contract.is_published? %>
16
18
  <%= link_to t('fine_print.contract.actions.unpublish'),
17
- unpublish_contract_path(@contract), :method => :put, :data => {
18
- :confirm => t('fine_print.contract.actions.confirm.unpublish')},
19
- :class => 'fine_print link' %>
19
+ unpublish_contract_path(@contract),
20
+ method: :put,
21
+ data: {
22
+ confirm: t('fine_print.contract.actions.confirm.unpublish')
23
+ },
24
+ class: 'fine_print link' %>
20
25
  <% else %>
21
26
  <%= link_to t('fine_print.contract.actions.publish'),
22
- publish_contract_path(@contract), :method => :put, :data => {
23
- :confirm => t('fine_print.contract.actions.confirm.publish')},
24
- :class => 'fine_print link' %> |
27
+ publish_contract_path(@contract),
28
+ method: :put,
29
+ data: {
30
+ confirm: t('fine_print.contract.actions.confirm.publish')
31
+ },
32
+ class: 'fine_print link' %> |
25
33
  <% end %>
26
- <%= link_to t('fine_print.contract.actions.delete'), @contract, :method => :delete,
27
- :data => {:confirm => t('fine_print.contract.actions.confirm.delete')},
28
- :class => 'fine_print link' %>
34
+ <%= link_to t('fine_print.contract.actions.delete'),
35
+ @contract,
36
+ method: :delete,
37
+ date: {
38
+ confirm: t('fine_print.contract.actions.confirm.delete')
39
+ },
40
+ class: 'fine_print link' %>
29
41
  <% else %>
30
42
  <%= link_to t('fine_print.contract.actions.new_version'),
31
- new_version_contract_path(@contract), :method => :post,
32
- :class => 'fine_print link' %> |
43
+ new_version_contract_path(@contract),
44
+ method: :post,
45
+ class: 'fine_print link' %> |
33
46
  <%= link_to t('fine_print.contract.actions.signatures'),
34
- contract_signatures_path(@contract), :class => 'fine_print link' %>
47
+ contract_signatures_path(@contract),
48
+ class: 'fine_print link' %>
35
49
  <% end %>
36
- | <%= link_to t('fine_print.contract.actions.list'), contracts_path,
37
- :class => 'fine_print link' %>
50
+ | <%= link_to t('fine_print.contract.actions.list'),
51
+ contracts_path,
52
+ class: 'fine_print link' %>
38
53
  </div>
@@ -1,4 +1,4 @@
1
- <%= form_for([@contract, @signature], :html => {:class => 'fine_print'}) do |f| %>
1
+ <%= form_for([@contract, @signature], html: { class: 'fine_print' }) do |f| %>
2
2
  <% if @signature.errors.any? %>
3
3
  <div id='error_explanation' class='fine_print errors'>
4
4
  <h4 class='fine_print heading'>
@@ -14,13 +14,16 @@
14
14
  <% end %>
15
15
 
16
16
  <div class='field'>
17
- <%= f.label :accept, t('fine_print.signature.actions.accept'), :class => 'fine_print' %>
18
- <%= check_box_tag :signature_accept, :class => 'fine_print check_box' %>
17
+ <%= f.label :accept,
18
+ t('fine_print.signature.actions.accept'),
19
+ class: 'fine_print' %>
20
+ <%= check_box_tag :signature_accept, class: 'fine_print check_box' %>
19
21
  </div>
20
22
 
21
23
  <br>
22
24
 
23
25
  <div class='actions'>
24
- <%= f.submit t('fine_print.signature.actions.sign'), :class => 'fine_print submit' %>
26
+ <%= f.submit t('fine_print.signature.actions.sign'),
27
+ class: 'fine_print submit' %>
25
28
  </div>
26
29
  <% end %>
@@ -1,7 +1,11 @@
1
1
  <h1 class='fine_print heading'>
2
- <%= t('fine_print.signature.status.for_contract', contract: link_to(
3
- "#{@contract.title} #{t('fine_print.contract.status.version',
4
- version: @contract.version.to_s)}", @contract)).html_safe %>
2
+ <%= t('fine_print.signature.status.for_contract',
3
+ contract: link_to(
4
+ "#{@contract.title} #{t('fine_print.contract.status.version',
5
+ version: @contract.version.to_s)}",
6
+ @contract
7
+ )
8
+ ).html_safe %>
5
9
  </h1>
6
10
 
7
11
  <div class='fine_print signature_index'>
@@ -19,11 +23,15 @@
19
23
  <td><%= signature.user_type %>&nbsp;</td>
20
24
  <td>&nbsp;<%= signature.user_id %>&nbsp;</td>
21
25
  <td>&nbsp;<%= l signature.created_at, format: :fine_print %>&nbsp;</td>
22
- <td>&nbsp;<%= link_to t('fine_print.signature.actions.delete'),
23
- signature, :method => :delete,
24
- :data => {
25
- :confirm => t('fine_print.signature.actions.confirm.delete')
26
- }, :class => 'fine_print link' %>
26
+ <td>&nbsp;<%= link_to(
27
+ t('fine_print.signature.actions.delete'),
28
+ signature,
29
+ method: :delete,
30
+ data: {
31
+ confirm: t('fine_print.signature.actions.confirm.delete')
32
+ }
33
+ class: 'fine_print link'
34
+ ) %>
27
35
  </td>
28
36
  </tr>
29
37
  <% end %>
@@ -33,7 +41,7 @@
33
41
 
34
42
  <div class='fine_print links'>
35
43
  <%= link_to t('fine_print.contract.actions.list'), contracts_path,
36
- :class => 'fine_print link' %>
44
+ class: 'fine_print link' %>
37
45
  </div>
38
46
 
39
47
  </div>
@@ -1,13 +1,15 @@
1
1
  <% if FinePrint.signed_any_version_of_contract?(@user, @contract) %>
2
2
  <div class='fine_print notice'>
3
- <h4 class='fine_print heading'><%= t('fine_print.signature.status.new_version',
4
- contract: @contract.title) %></h4>
3
+ <h4 class='fine_print heading'>
4
+ <%= t('fine_print.signature.status.new_version',
5
+ contract: @contract.title) %>
6
+ </h4>
5
7
  </div>
6
8
  <% end %>
7
9
 
8
10
  <div class='fine_print contract'>
9
- <%= render :partial => 'fine_print/contracts/show',
10
- :locals => {:contract => @contract} %>
11
+ <%= render partial: 'fine_print/contracts/show',
12
+ locals: { contract: @contract } %>
11
13
  </div>
12
14
 
13
15
  <div class='fine_print new_signature'>
@@ -1,57 +1,60 @@
1
- # Change the settings below to suit your needs
2
- # All options are initially set to their default values
3
1
  FinePrint.configure do |config|
4
2
 
5
- # Engine Configuration
6
- # Must be set in an initializer
3
+ # Engine Configuration: Must be set in an initializer
7
4
 
8
- # Proc called with a controller as self.
9
- # Returns the current user.
5
+ # Layout to be used for FinePrint's controllers
6
+ # Default: 'application'
7
+ config.layout = 'application'
8
+
9
+ # Array of custom helpers for FinePrint's controllers
10
+ # Default: [] (no custom helpers)
11
+ config.helpers = []
12
+
13
+ # Proc called with a controller as self. Returns the current user.
10
14
  # Default: lambda { current_user }
11
15
  config.current_user_proc = lambda { current_user }
12
16
 
13
17
  # Proc called with a user as argument and a controller as self.
14
18
  # This proc is called when a user tries to access FinePrint's controllers.
15
- # Should raise and exception, render or redirect unless the user can manage contracts.
16
- # Contract managers can create and edit agreements and terminate accepted agreements.
17
- # The default renders 403 Forbidden for all users.
19
+ # Should raise and exception, render or redirect unless the user is a manager
20
+ # or admin. Contract managers can create and edit agreements and terminate
21
+ # accepted agreements. The default renders 403 Forbidden for all users.
18
22
  # Note: Proc must account for nil users, if current_user_proc returns nil.
19
- # Default: lambda { |user| false || head(:forbidden) }
20
- config.can_manage_proc = lambda { |user| false || head(:forbidden) }
23
+ # Default: lambda { |user| head(:forbidden) }
24
+ config.authenticate_manager_proc = lambda { |user| head(:forbidden) }
21
25
 
22
26
  # Proc called with a user as argument and a controller as self.
23
- # This proc is called to check that the given user is allowed to sign contracts.
24
- # Should raise and exception, render or redirect unless the user can sign contracts.
25
- # You might want to redirect users to a login page if they are not signed in.
26
- # The default renders 401 Unauthorized for nil users.
27
+ # This proc is called before FinePrint determines if contracts need to be
28
+ # signed. If it returns true, FinePrint will proceed with its checks and
29
+ # potentially call the redirect_to_contracts_proc with the user as argument.
30
+ # If it returns false, renders or redirects, FinePrint will stop its checks.
31
+ # Note that returning false will allow the user to proceed without signing
32
+ # contracts, unless another before_filter renders or redirects (to a login
33
+ # page, for example). The default renders 401 Unauthorized for nil users and
34
+ # checks all others for contracts to be signed.
27
35
  # Default: lambda { |user| !user.nil? || head(:unauthorized) }
28
- config.can_sign_proc = lambda { |user| !user.nil? || head(:unauthorized) }
29
-
30
- # Layout to be used for FinePrint's controllers
31
- # Default: 'application'
32
- config.layout = 'application'
33
-
34
- # Array of custom helpers for FinePrint's controllers
35
- # Default: [] (no custom helpers)
36
- config.helpers = []
36
+ config.authenticate_user_proc = lambda { |user| !user.nil? || \
37
+ head(:unauthorized) }
37
38
 
38
39
  # Controller Configuration
39
- # Can be set either in an initializer or passed as options to `fine_print_require`
40
+ # Can be set in this initializer or passed as options to `fine_print_require`
40
41
 
41
- # Proc called with a user and an array of contract ids as arguments and a controller as self.
42
- # This proc is called when a user tries to access a resource protected by FinePrint,
43
- # but has not signed all the required contracts.
44
- # Should raise and exception, render or redirect the user.
45
- # The `contract_ids` variable contains the contract ids that need to be signed.
42
+ # Proc called with a user and an array of contracts as arguments and a
43
+ # controller as self. This proc is called when a user tries to access a
44
+ # resource protected by FinePrint, but has not signed all the required
45
+ # contracts. Should redirect the user, render or raise an exception.
46
+ # The `contracts` argument contains the contracts that need to be signed.
46
47
  # The default redirects users to FinePrint's contract signing views.
47
- # The `fine_print_return` method can be used to return from a redirect made here.
48
- # Default: lambda { |user, contract_ids|
48
+ # The `fine_print_return` method can be used to return from this redirect.
49
+ # Default: lambda { |user, contracts|
49
50
  # redirect_to(fine_print.new_contract_signature_path(
50
- # :contract_id => contract_ids.first
51
+ # contract_id: contracts.first.id
51
52
  # ))
52
53
  # }
53
- config.must_sign_proc = lambda { |user, contract_ids| redirect_to(
54
- fine_print.new_contract_signature_path(:contract_id => contract_ids.first)
55
- ) }
54
+ config.redirect_to_contracts_proc = lambda { |user, contracts|
55
+ redirect_to(
56
+ fine_print.new_contract_signature_path(contract_id: contracts.first.id)
57
+ )
58
+ }
56
59
 
57
60
  end