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,5 +1,5 @@
1
1
  FactoryGirl.define do
2
- factory :fine_print_contract, :class => FinePrint::Contract do
2
+ factory :fine_print_contract, class: FinePrint::Contract do
3
3
  name { Faker::Lorem.words.join('_') }
4
4
  title { Faker::Lorem.words.join(' ').capitalize }
5
5
  content { Faker::Lorem.paragraphs.join("\n") }
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
- factory :fine_print_signature, :class => FinePrint::Signature do
3
- association :contract, :factory => [:fine_print_contract, :published]
2
+ factory :fine_print_signature, class: FinePrint::Signature do
3
+ association :contract, factory: [:fine_print_contract, :published]
4
4
 
5
5
  transient do
6
6
  user_factory :user
@@ -1,4 +1,4 @@
1
1
  FactoryGirl.define do
2
- factory :user, :class => DummyUser do
2
+ factory :user, class: DummyUser do
3
3
  end
4
4
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module FinePrint
4
+ module ActionController
5
+ describe Base, type: :lib do
6
+ let!(:controller) { ::ActionController::Base.new }
7
+ let!(:dummy_controller) { DummyModelsController.new }
8
+
9
+ it 'must add fine_print_sign to ActionController instances' do
10
+ expect(controller).to respond_to(:fine_print_require)
11
+ expect(dummy_controller).to respond_to(:fine_print_require)
12
+ end
13
+
14
+ it 'must add fine_print_return to ActionController instances' do
15
+ expect(controller.respond_to?(:fine_print_return, true)).to eq true
16
+ expect(dummy_controller.respond_to?(:fine_print_return, true)).to eq true
17
+ end
18
+
19
+ it 'must add fine_print_require to ActionController and subclasses' do
20
+ expect(controller.class).to respond_to(:fine_print_require)
21
+ expect(dummy_controller.class).to respond_to(:fine_print_require)
22
+ end
23
+
24
+ it 'must add fine_print_skip to ActionController and subclasses' do
25
+ expect(controller.class).to respond_to(:fine_print_skip)
26
+ expect(dummy_controller.class).to respond_to(:fine_print_skip)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,15 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FinePrint do
3
+ describe FinePrint, type: :lib do
4
4
  before :each do
5
- @alpha_1 = FactoryGirl.create(:fine_print_contract, :published, :name => 'alpha')
6
- @beta_1 = FactoryGirl.create(:fine_print_contract, :published, :name => 'beta')
5
+ @alpha_1 = FactoryGirl.create(:fine_print_contract, :published,
6
+ name: 'alpha')
7
+ @beta_1 = FactoryGirl.create(:fine_print_contract, :published,
8
+ name: 'beta')
7
9
 
8
10
  @user = DummyUser.create
9
- @alpha_1_sig = FactoryGirl.create(:fine_print_signature, :contract => @alpha_1,
10
- :user => @user)
11
- @beta_1_sig = FactoryGirl.create(:fine_print_signature, :contract => @beta_1,
12
- :user => @user)
11
+ @alpha_1_sig = FactoryGirl.create(:fine_print_signature, contract: @alpha_1,
12
+ user: @user)
13
+ @beta_1_sig = FactoryGirl.create(:fine_print_signature, contract: @beta_1,
14
+ user: @user)
13
15
 
14
16
  @alpha_2 = @alpha_1.new_version
15
17
  @alpha_2.update_attribute(:content, 'foo')
@@ -26,13 +28,14 @@ describe FinePrint do
26
28
  end
27
29
 
28
30
  it 'gets signed contracts' do
29
- expect(FinePrint.get_signed_contract_ids(@user)).to(
30
- eq [@beta_1.id])
31
+ expect(FinePrint.signed_contracts_for(@user)).to(
32
+ eq [@beta_1]
33
+ )
31
34
  end
32
35
 
33
36
  it 'gets unsigned contracts' do
34
- expect(FinePrint.get_unsigned_contract_ids(@user, @alpha_2.id, @beta_1.id)).to(
35
- eq [@alpha_2.id])
37
+ names = [@alpha_2, @beta_1].collect{|c| c.name}
38
+ expect(FinePrint.unsigned_contracts_for(@user, name: names)).to eq [@alpha_2]
36
39
  end
37
40
 
38
41
  it 'allows users to sign contracts' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module FinePrint
4
- describe Contract do
4
+ describe Contract, type: :model do
5
5
  it 'can be published and unpublished' do
6
6
  contract = FactoryGirl.create(:fine_print_contract)
7
7
  expect(contract.is_published?).to eq false
@@ -36,7 +36,7 @@ module FinePrint
36
36
  expect(contract.is_published?).to eq true
37
37
  expect(contract.signatures).to be_empty
38
38
 
39
- ua = FactoryGirl.create(:fine_print_signature, :contract => contract)
39
+ ua = FactoryGirl.create(:fine_print_signature, contract: contract)
40
40
  contract.reload
41
41
  expect(contract.signatures).not_to be_empty
42
42
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module FinePrint
4
- describe Signature do
4
+ describe Signature, type: :model do
5
5
  it "can't be associated with unpublished contracts" do
6
6
  contract = FactoryGirl.create(:fine_print_contract)
7
7
  expect(contract.is_published?).to eq false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fine_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-23 00:00:00.000000000 Z
12
+ date: 2015-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -171,7 +171,8 @@ files:
171
171
  - config/routes.rb
172
172
  - db/migrate/0_install_fine_print.rb
173
173
  - lib/fine_print.rb
174
- - lib/fine_print/controller_includes.rb
174
+ - lib/fine_print/action_controller/base.rb
175
+ - lib/fine_print/configuration.rb
175
176
  - lib/fine_print/engine.rb
176
177
  - lib/fine_print/version.rb
177
178
  - lib/tasks/fine_print_tasks.rake
@@ -219,7 +220,7 @@ files:
219
220
  - spec/factories/fine_print/contract.rb
220
221
  - spec/factories/fine_print/signature.rb
221
222
  - spec/factories/user.rb
222
- - spec/lib/fine_print/controller_includes_spec.rb
223
+ - spec/lib/fine_print/action_controller/base_spec.rb
223
224
  - spec/lib/fine_print_spec.rb
224
225
  - spec/models/contract_spec.rb
225
226
  - spec/models/signature_spec.rb
@@ -294,7 +295,7 @@ test_files:
294
295
  - spec/factories/fine_print/contract.rb
295
296
  - spec/factories/fine_print/signature.rb
296
297
  - spec/factories/user.rb
297
- - spec/lib/fine_print/controller_includes_spec.rb
298
+ - spec/lib/fine_print/action_controller/base_spec.rb
298
299
  - spec/lib/fine_print_spec.rb
299
300
  - spec/models/contract_spec.rb
300
301
  - spec/models/signature_spec.rb
@@ -1,93 +0,0 @@
1
- module FinePrint
2
- module ControllerIncludes
3
- def self.included(base)
4
- base.extend(ClassMethods)
5
- end
6
-
7
- # Accepts a user, an array of contract ids to be signed and an options hash
8
- # Calls the sign_proc with the given parameters
9
- def fine_print_sign(user, *args)
10
- options = args.last.is_a?(Hash) ? args.pop : {}
11
- contract_ids = args.flatten.collect{|n| n.to_s}
12
-
13
- blk = options[:must_sign_proc] || FinePrint.must_sign_proc
14
-
15
- # Use action_interceptor to save the current url
16
- store_url key: :fine_print_return_to
17
-
18
- instance_exec user, contract_ids, &blk
19
- end
20
-
21
- # Accepts no arguments
22
- # Redirects the user back to the url they were at before
23
- # one of FinePrint's procs redirected them
24
- def fine_print_return
25
- redirect_back key: :fine_print_return_to
26
- end
27
-
28
- protected
29
-
30
- def fine_print_skipped_contract_names
31
- @fine_print_skipped_contract_names ||= []
32
- end
33
-
34
- module ClassMethods
35
- # For the following methods, names passed as Symbols are converted to Strings.
36
-
37
- # Accepts an array of contract names and an options hash
38
- # Adds a before_filter to the current controller that will check if the
39
- # current user has signed the given contracts and call the sign_proc if appropriate
40
- # Options relevant to FinePrint are passed to fine_print_sign, while
41
- # other options are passed to the before_filter
42
- def fine_print_require(*args)
43
- options = args.last.is_a?(Hash) ? args.pop : {}
44
-
45
- filter_options = options.except(*FinePrint::CONTROLLER_OPTIONS)
46
- fine_print_options = options.slice(*FinePrint::CONTROLLER_OPTIONS)
47
-
48
- # Convert names to an array of Strings
49
- contract_names = args.flatten.collect{|c| c.to_s}
50
-
51
- class_eval do
52
- before_filter(filter_options) do |controller|
53
- skipped_contract_names = controller.fine_print_skipped_contract_names
54
- unskipped_contract_names = contract_names - skipped_contract_names
55
-
56
- # Return quietly if all contracts skipped
57
- next if unskipped_contract_names.blank?
58
-
59
- user = instance_exec &FinePrint.current_user_proc
60
-
61
- contract_ids = FinePrint.contract_names_to_ids(unskipped_contract_names).flatten
62
-
63
- unsigned_contract_ids = FinePrint.get_unsigned_contract_ids(user, contract_ids)
64
-
65
- # Return quietly if no contracts left to sign
66
- next if unsigned_contract_ids.blank?
67
-
68
- controller.fine_print_sign(user, unsigned_contract_ids, fine_print_options)
69
- end
70
- end
71
- end
72
-
73
- # Accepts an array of contract names and an options hash
74
- # Excludes the given contracts from the `fine_print_require`
75
- # check for this controller and subclasses
76
- # Options are passed to prepend_before_filter
77
- def fine_print_skip(*args)
78
- options = args.last.is_a?(Hash) ? args.pop : {}
79
-
80
- # Convert names to an array of Strings
81
- contract_names = args.flatten.collect{|c| c.to_s}
82
-
83
- class_eval do
84
- prepend_before_filter(options) do |controller|
85
- controller.fine_print_skipped_contract_names.push(*contract_names)
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end
92
-
93
- ActionController::Base.send :include, FinePrint::ControllerIncludes
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module FinePrint
4
- describe ControllerIncludes do
5
- it 'must add fine_print_sign to ActionController instances' do
6
- expect(ActionController::Base.new.respond_to? :fine_print_sign).to eq true
7
- expect(DummyModelsController.new.respond_to? :fine_print_sign).to eq true
8
- end
9
-
10
- it 'must add fine_print_return to ActionController instances' do
11
- expect(ActionController::Base.new.respond_to?(:fine_print_return, true)).to eq true
12
- expect(DummyModelsController.new.respond_to?(:fine_print_return, true)).to eq true
13
- end
14
-
15
- it 'must add fine_print_require to ActionController and subclasses' do
16
- expect(ActionController::Base.respond_to? :fine_print_require).to eq true
17
- expect(DummyModelsController.respond_to? :fine_print_require).to eq true
18
- end
19
-
20
- it 'must add fine_print_skip to ActionController and subclasses' do
21
- expect(ActionController::Base.respond_to? :fine_print_skip).to eq true
22
- expect(DummyModelsController.respond_to? :fine_print_skip).to eq true
23
- end
24
- end
25
- end