fine_print 1.4.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -2
  3. data/Rakefile +0 -1
  4. data/app/assets/javascripts/fine_print/application.js +0 -1
  5. data/app/assets/stylesheets/fine_print/application.css +0 -1
  6. data/app/controllers/fine_print/application_controller.rb +9 -4
  7. data/app/controllers/fine_print/contracts_controller.rb +16 -12
  8. data/app/controllers/fine_print/home_controller.rb +5 -0
  9. data/app/controllers/fine_print/signatures_controller.rb +44 -2
  10. data/app/models/fine_print/contract.rb +17 -45
  11. data/app/models/fine_print/signature.rb +4 -3
  12. data/app/views/fine_print/contracts/_show.html.erb +11 -0
  13. data/app/views/fine_print/contracts/edit.html.erb +1 -1
  14. data/app/views/fine_print/contracts/index.html.erb +12 -14
  15. data/app/views/fine_print/contracts/new_version.html.erb +1 -1
  16. data/app/views/fine_print/contracts/show.html.erb +18 -29
  17. data/app/views/fine_print/signatures/_form.html.erb +21 -0
  18. data/app/views/fine_print/signatures/index.html.erb +3 -7
  19. data/app/views/fine_print/signatures/new.html.erb +13 -0
  20. data/config/initializers/fine_print.rb +36 -33
  21. data/config/routes.rb +5 -5
  22. data/db/migrate/0_install_fine_print.rb +2 -3
  23. data/lib/fine_print/controller_includes.rb +41 -67
  24. data/lib/fine_print/engine.rb +3 -0
  25. data/lib/fine_print/version.rb +1 -1
  26. data/lib/fine_print.rb +48 -57
  27. data/spec/controllers/contracts_controller_spec.rb +98 -98
  28. data/spec/controllers/home_controller_spec.rb +7 -5
  29. data/spec/controllers/signatures_controller_spec.rb +48 -19
  30. data/spec/dummy/app/models/dummy_user.rb +0 -1
  31. data/spec/dummy/config/initializers/fine_print.rb +2 -1
  32. data/spec/dummy/db/development.sqlite3 +0 -0
  33. data/spec/dummy/db/test.sqlite3 +0 -0
  34. data/spec/dummy/log/development.log +31970 -0
  35. data/spec/dummy/log/test.log +71587 -0
  36. data/spec/lib/fine_print/controller_includes_spec.rb +9 -14
  37. data/spec/lib/fine_print_spec.rb +15 -9
  38. data/spec/models/contract_spec.rb +17 -25
  39. data/spec/models/signature_spec.rb +4 -14
  40. data/spec/spec_helper.rb +1 -2
  41. metadata +33 -4
  42. data/app/views/fine_print/home/index.html.erb +0 -16
  43. data/lib/fine_print/security_transgression.rb +0 -3
@@ -18,10 +18,9 @@ class InstallFinePrint < ActiveRecord::Migration
18
18
  t.timestamps
19
19
  end
20
20
 
21
- add_index :fine_print_signatures, :contract_id
22
- add_index :fine_print_signatures,
23
- [:user_id, :user_type, :contract_id],
21
+ add_index :fine_print_signatures, [:user_id, :user_type, :contract_id],
24
22
  :name => 'index_fine_print_s_on_u_id_and_u_type_and_c_id',
25
23
  :unique => true
24
+ add_index :fine_print_signatures, :contract_id
26
25
  end
27
26
  end
@@ -4,106 +4,80 @@ module FinePrint
4
4
  base.extend(ClassMethods)
5
5
  end
6
6
 
7
- # For the following methods, names passed as Symbols are converted to Strings.
8
-
9
- # Accepts an array of contract names
10
- # Returns nil if the array is blank or the current user cannot sign contracts
11
- # Otherwise, returns the contract names that the user hasn't signed yet
12
- def fine_print_get_unsigned_contract_names(*contract_names)
13
- # Convert names to an array of Strings
14
- names = contract_names.flatten.collect{|n| n.to_s}
15
-
16
- user = FinePrint.current_user_proc.call(self)
17
-
18
- # If the user isn't signed in, they can't sign a contract
19
- # Since there may be some pages that both logged in and non-logged in users
20
- # can visit, we just return quietly instead of raising an exception
21
- return nil if names.blank? || !FinePrint.can_sign?(user)
22
-
23
- # Ignore contracts that don't yet exist or aren't yet published (happens
24
- # when adding code that requires a new contract but before that contract
25
- # has been added and published)
26
- FinePrint.get_unsigned_contract_names(user, names)
27
- .reject{|name| FinePrint.get_contract(name).blank?}
28
- end
29
-
30
- # Accepts an array of unsigned contract names and an options hash
31
- # Unless the array of unsigned contract names is blank or the request url is
32
- # already the contract_redirect_path, it saves the current request path and
33
- # redirects the user to the `contract_redirect_path`, with
34
- # `contract_param_name` containing the unsigned contract names
35
- def fine_print_redirect(*args)
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)
36
10
  options = args.last.is_a?(Hash) ? args.pop : {}
37
- unsigned_contract_names = args.flatten
38
- return if unsigned_contract_names.nil? ||\
39
- unsigned_contract_names.all? { |n| n.blank? }
40
-
41
- path = options[:contract_redirect_path] || FinePrint.contract_redirect_path
42
- param_name = options[:contract_param_name] || FinePrint.contract_param_name
11
+ contract_ids = args.flatten.collect{|n| n.to_s}
43
12
 
44
- # http://stackoverflow.com/a/6561953
45
- redirect_path = path + (path.include?('?') ? '&' : '?') +\
46
- {param_name.to_sym => unsigned_contract_names}.to_query
13
+ blk = options[:must_sign_proc] || FinePrint.must_sign_proc
47
14
 
48
- # Prevent redirect loop
49
- return if view_context.current_page?(redirect_path)
50
-
51
- # http://stackoverflow.com/a/2165727/1664216
52
- session[:fine_print_return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
53
- redirect_to redirect_path
15
+ # Use action_interceptor to save the current url
16
+ with_interceptor { instance_exec user, contract_ids, &blk }
54
17
  end
55
18
 
56
19
  # Accepts no arguments
57
- # Redirects the user to the path saved by either
58
- # `fine_print_get_signatures` or `fine_print_redirect`
20
+ # Redirects the user back to the url they were at before
21
+ # one of FinePrint's procs redirected them
59
22
  def fine_print_return
60
- redirect_to session.delete(:fine_print_return_to) || root_path
23
+ redirect_back
61
24
  end
62
-
25
+
63
26
  protected
64
27
 
65
- def fine_print_skipped_contract_names
66
- @fine_print_skipped_contract_names ||= []
28
+ def fine_print_skipped_contract_ids
29
+ @fine_print_skipped_contract_ids ||= []
67
30
  end
68
31
 
69
32
  module ClassMethods
33
+ # For the following methods, names passed as Symbols are converted to Strings.
34
+
70
35
  # Accepts an array of contract names and an options hash
71
36
  # Adds a before_filter to the current controller that will check if the
72
- # current user has signed the given contracts and redirect them to
73
- # `contract_redirect_path` if appropriate
74
- # Options relevant to FinePrint are passed to fine_print_redirect, while
37
+ # current user has signed the given contracts and call the sign_proc if appropriate
38
+ # Options relevant to FinePrint are passed to fine_print_sign, while
75
39
  # other options are passed to the before_filter
76
- def fine_print_get_signatures(*args)
40
+ def fine_print_require(*args)
77
41
  options = args.last.is_a?(Hash) ? args.pop : {}
78
42
 
79
- filter_options = options.except(*FinePrint::CONTRACT_OPTIONS)
80
- fine_print_options = options.slice(*FinePrint::CONTRACT_OPTIONS)
43
+ filter_options = options.except(*FinePrint::CONTROLLER_OPTIONS)
44
+ fine_print_options = options.slice(*FinePrint::CONTROLLER_OPTIONS)
81
45
 
82
46
  # Convert names to an array of Strings
83
- contract_names = args.flatten.collect{|n| n.to_s}
47
+ contract_ids = FinePrint.contract_names_to_ids(args).flatten
84
48
 
85
49
  class_eval do
86
50
  before_filter(filter_options) do |controller|
87
- controller.fine_print_redirect(
88
- controller.fine_print_get_unsigned_contract_names(contract_names - controller.fine_print_skipped_contract_names),
89
- fine_print_options)
51
+ skipped_contract_ids = controller.fine_print_skipped_contract_ids
52
+ unskipped_contract_ids = contract_ids - skipped_contract_ids
53
+
54
+ # Return quietly if all contracts skipped
55
+ next if unskipped_contract_ids.blank?
56
+
57
+ user = instance_exec &FinePrint.current_user_proc
58
+
59
+ unsigned_contract_ids = FinePrint.get_unsigned_contract_ids(
60
+ user, unskipped_contract_ids)
61
+
62
+ # Return quietly if no contracts left to sign
63
+ next if unsigned_contract_ids.blank?
64
+
65
+ controller.fine_print_sign(user, unsigned_contract_ids, fine_print_options)
90
66
  end
91
67
  end
92
68
  end
93
69
 
94
70
  # Accepts an array of contract names and an options hash
95
- # Excludes the given contracts from the `fine_print_get_signatures` check for
96
- # this controller and subclasses
71
+ # Excludes the given contracts from the `fine_print_require`
72
+ # check for this controller and subclasses
97
73
  # Options are passed to prepend_before_filter
98
- def fine_print_skip_signatures(*args)
74
+ def fine_print_skip(*args)
99
75
  options = args.last.is_a?(Hash) ? args.pop : {}
100
76
 
101
- # Convert all names to string
102
- names = args.flatten.collect{|n| n.to_s}
103
-
104
77
  class_eval do
105
78
  prepend_before_filter(options) do |controller|
106
- controller.fine_print_skipped_contract_names.push(*names)
79
+ contract_ids = FinePrint.contract_names_to_ids(args).flatten
80
+ controller.fine_print_skipped_contract_ids.push(*contract_ids)
107
81
  end
108
82
  end
109
83
  end
@@ -1,3 +1,6 @@
1
+ require 'action_interceptor'
2
+ require 'squeel'
3
+
1
4
  module FinePrint
2
5
  class Engine < ::Rails::Engine
3
6
  isolate_namespace FinePrint
@@ -1,3 +1,3 @@
1
1
  module FinePrint
2
- VERSION = '1.4.1'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/fine_print.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'fine_print/engine'
2
- require 'fine_print/security_transgression'
3
2
  require 'fine_print/controller_includes'
4
3
 
5
4
  module FinePrint
@@ -8,18 +7,17 @@ module FinePrint
8
7
  # Can be set in initializer only
9
8
  ENGINE_OPTIONS = [
10
9
  :current_user_proc,
11
- :user_admin_proc,
12
- :user_can_sign_proc
10
+ :can_manage_proc,
11
+ :can_sign_proc
13
12
  ]
14
13
 
15
- # Can be set in initializer or passed as an argument to either
16
- # `fine_print_get_signatures` or `fine_print_redirect`
17
- CONTRACT_OPTIONS = [
18
- :contract_param_name,
19
- :contract_redirect_path
14
+ # Can be set in initializer or passed as an argument
15
+ # to FinePrint controller methods
16
+ CONTROLLER_OPTIONS = [
17
+ :must_sign_proc
20
18
  ]
21
19
 
22
- (ENGINE_OPTIONS + CONTRACT_OPTIONS).each do |option|
20
+ (ENGINE_OPTIONS + CONTROLLER_OPTIONS).each do |option|
23
21
  mattr_accessor option
24
22
  end
25
23
 
@@ -27,28 +25,23 @@ module FinePrint
27
25
  yield self
28
26
  end
29
27
 
30
- # Gets a contract, given either the contract's object, ID or name
28
+ # Gets a contract, given either the contract object, ID or name
31
29
  # If given a name, it returns the latest published version of that contract
32
30
  # - contract - can be a Contract object, its ID, or its name (String/Symbol)
33
31
  def self.get_contract(reference)
34
- ref = Integer(reference) rescue reference
35
- case ref
36
- when Contract
37
- ref
38
- when Integer
39
- Contract.find(ref)
40
- when String, Symbol
41
- Contract.where(:name => ref.to_s).published.first
42
- end
32
+ return reference if reference.is_a? Contract
33
+ num = Integer(reference) rescue nil
34
+ return Contract.find(num) if num
35
+ contract = Contract.where(:name => reference.to_s).published.first
36
+ return contract if contract
37
+ raise ActiveRecord::RecordNotFound, "Couldn't find Contract with 'name'=#{reference.to_s}"
43
38
  end
44
39
 
45
40
  # Records that the given user has signed the given contract
46
41
  # - user - the user in question
47
42
  # - contract - can be a Contract object, its ID, or its name (String/Symbol)
48
43
  def self.sign_contract(user, contract)
49
- raise_unless_can_sign(user)
50
44
  contract = get_contract(contract)
51
- raise IllegalState, 'Contract not found' if contract.nil?
52
45
 
53
46
  Signature.create do |signature|
54
47
  signature.user = user
@@ -60,57 +53,55 @@ module FinePrint
60
53
  # - user - the user in question
61
54
  # - contract - can be a Contract object, its ID, or its name (String/Symbol)
62
55
  def self.signed_contract?(user, contract)
63
- raise_unless_can_sign(user)
64
56
  contract = get_contract(contract)
65
57
 
66
- !contract.signatures.where(:user_id => user.id,
67
- :user_type => user.class.name).first.nil?
58
+ contract.signatures.where(:user_id => user.id,
59
+ :user_type => user.class.name).exists?
68
60
  end
69
61
 
70
62
  # Returns true iff the given user has signed any version of the given contract
71
63
  # - user - the user in question
72
64
  # - contract - can be a Contract object, its ID, or its name (String/Symbol)
73
- def self.signed_any_contract_version?(user, contract)
74
- raise_unless_can_sign(user)
65
+ def self.signed_any_version_of_contract?(user, contract)
75
66
  contract = get_contract(contract)
76
- !Signature.joins(:contract)
77
- .where(:fine_print_contracts => {:name => contract.name},
78
- :user_type => user.class.name,
79
- :user_id => user.id).first.nil?
80
- end
81
67
 
82
- # Returns an array of names for the contracts whose latest published
83
- # version the given user has not signed.
84
- # - user - the user in question
85
- # - names - contract names to check
86
- def self.get_unsigned_contract_names(user, *names)
87
- raise_unless_can_sign(user)
88
- names = names.flatten.collect{|name| name.to_s}
89
- return [] if names.blank?
90
-
91
- signed_contracts = Contract
92
- .joins(:signatures)
93
- .where({:name => names,
94
- :fine_print_signatures => {:user_id => user.id,
95
- :user_type => user.class.name}}).latest
96
- signed_contract_names = signed_contracts.to_a.collect{|c| c.name}
97
-
98
- return names - signed_contract_names
68
+ contract.same_name.includes(:signatures).any? do |c|
69
+ c.signatures.where(:user_id => user.id,
70
+ :user_type => user.class.name).exists?
71
+ end
99
72
  end
100
73
 
101
- def self.can_sign?(user)
102
- user_can_sign_proc.call(user)
74
+ # Converts an array of contract names into an array containing
75
+ # the latest contract id for each given name.
76
+ def self.contract_names_to_ids(*contract_names)
77
+ names = contract_names.flatten
78
+ Contract.latest.where(:name => names).pluck(:id)
103
79
  end
104
80
 
105
- def self.is_admin?(user)
106
- !user.nil? && user_admin_proc.call(user)
81
+ # Returns an array of ids for the contracts among those given
82
+ # whose latest published version the user has signed.
83
+ # - user - the user in question
84
+ # - contract_ids - contract ids to check
85
+ # If no contract ids are provided, all latest contracts are checked
86
+ def self.get_signed_contract_ids(user, *contract_ids)
87
+ ids = contract_ids.flatten
88
+ ids = Contract.published.latest.pluck(:id) if ids.blank?
89
+
90
+ Signature.where(:user_id => user.id,
91
+ :user_type => user.class.name,
92
+ :contract_id => ids).pluck(:contract_id)
107
93
  end
108
94
 
109
- def self.raise_unless_can_sign(user)
110
- raise IllegalState, 'User cannot sign contracts' unless can_sign?(user)
111
- end
95
+ # Returns an array of ids for the contracts among those given
96
+ # whose latest published version the user has not signed.
97
+ # - user - the user in question
98
+ # - contract_ids - contract ids to check
99
+ # If no contract ids are provided, all latest contracts are checked
100
+ def self.get_unsigned_contract_ids(user, *contract_ids)
101
+ ids = contract_ids.flatten
102
+ ids = Contract.published.latest.pluck(:id) if ids.blank?
112
103
 
113
- def self.raise_unless_admin(user)
114
- raise SecurityTransgression unless is_admin?(user)
104
+ ids - get_signed_contract_ids(user, ids)
115
105
  end
106
+
116
107
  end
@@ -1,43 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module FinePrint
4
- describe ContractsController do
4
+ describe ContractsController, :type => :controller do
5
5
  routes { FinePrint::Engine.routes }
6
6
 
7
- before do
7
+ before(:each) do
8
8
  setup_controller_spec
9
- @contract = FactoryGirl.create(:contract)
10
- @contract.reload
11
9
  end
12
10
 
11
+ let!(:contract) { FactoryGirl.create(:contract) }
12
+
13
13
  it "won't get index unless authorized" do
14
14
  expect { get :index, :use_route => :fine_print }
15
- .to raise_error(FinePrint::SecurityTransgression)
15
+ .to raise_error(ActionController::RoutingError)
16
16
 
17
17
  sign_in @user
18
18
  expect { get :index, :use_route => :fine_print }
19
- .to raise_error(FinePrint::SecurityTransgression)
19
+ .to raise_error(ActionController::RoutingError)
20
20
  end
21
21
 
22
22
  it 'must get index if authorized' do
23
23
  sign_in @admin
24
24
  get :index, :use_route => :fine_print
25
- assert_response :success
25
+ expect(response.status).to eq 200
26
26
  end
27
27
 
28
28
  it "won't get new unless authorized" do
29
29
  expect { get :new, :use_route => :fine_print }
30
- .to raise_error(FinePrint::SecurityTransgression)
30
+ .to raise_error(ActionController::RoutingError)
31
31
 
32
32
  sign_in @user
33
33
  expect { get :new, :use_route => :fine_print }
34
- .to raise_error(FinePrint::SecurityTransgression)
34
+ .to raise_error(ActionController::RoutingError)
35
35
  end
36
36
 
37
37
  it 'must get new if authorized' do
38
38
  sign_in @admin
39
39
  get :new, :use_route => :fine_print
40
- assert_response :success
40
+ expect(response.status).to eq 200
41
41
  end
42
42
 
43
43
  it "won't create unless authorized" do
@@ -47,12 +47,12 @@ module FinePrint
47
47
  attributes[:content] = 'Some content'
48
48
 
49
49
  expect { post :create, :contract => :attributes, :use_route => :fine_print }
50
- .to raise_error(FinePrint::SecurityTransgression)
50
+ .to raise_error(ActionController::RoutingError)
51
51
  expect(assigns(:contract)).to be_nil
52
52
 
53
53
  sign_in @user
54
54
  expect { post :create, :contract => :attributes, :use_route => :fine_print }
55
- .to raise_error(FinePrint::SecurityTransgression)
55
+ .to raise_error(ActionController::RoutingError)
56
56
  expect(assigns(:contract)).to be_nil
57
57
  end
58
58
 
@@ -64,7 +64,7 @@ module FinePrint
64
64
  attributes[:content] = 'Some content'
65
65
 
66
66
  post :create, :contract => attributes, :use_route => :fine_print
67
- assert_redirected_to assigns(:contract)
67
+ expect(response).to redirect_to assigns(:contract)
68
68
  expect(assigns(:contract).errors).to be_empty
69
69
  expect(assigns(:contract).name).to eq 'some_name'
70
70
  expect(assigns(:contract).title).to eq 'Some title'
@@ -72,152 +72,152 @@ module FinePrint
72
72
  end
73
73
 
74
74
  it "won't edit unless authorized" do
75
- expect { get :edit, :id => @contract.id, :use_route => :fine_print }
76
- .to raise_error(FinePrint::SecurityTransgression)
75
+ expect { get :edit, :id => contract.id, :use_route => :fine_print }
76
+ .to raise_error(ActionController::RoutingError)
77
77
 
78
78
  sign_in @user
79
- expect { get :edit, :id => @contract.id, :use_route => :fine_print }
80
- .to raise_error(FinePrint::SecurityTransgression)
79
+ expect { get :edit, :id => contract.id, :use_route => :fine_print }
80
+ .to raise_error(ActionController::RoutingError)
81
81
  end
82
82
 
83
83
  it 'must edit if authorized' do
84
84
  sign_in @admin
85
- get :edit, :id => @contract.id, :use_route => :fine_print
86
- assert_response :success
85
+ get :edit, :id => contract.id, :use_route => :fine_print
86
+ expect(response.status).to eq 200
87
87
  end
88
88
 
89
89
  it "won't update unless authorized" do
90
90
  attributes = Hash.new
91
- attributes[:name] = 'some_name'
92
- attributes[:title] = 'Some title'
93
- attributes[:content] = 'Some content'
94
- name = @contract.name
95
- title = @contract.title
96
- content = @contract.content
91
+ attributes[:name] = 'another_name'
92
+ attributes[:title] = 'Another title'
93
+ attributes[:content] = 'Another content'
94
+ name = contract.name
95
+ title = contract.title
96
+ content = contract.content
97
97
 
98
- expect { post :update, :id => @contract.id,
98
+ expect { post :update, :id => contract.id,
99
99
  :contract => attributes, :use_route => :fine_print }
100
- .to raise_error(FinePrint::SecurityTransgression)
101
- @contract.reload
102
- expect(@contract.name).to eq name
103
- expect(@contract.title).to eq title
104
- expect(@contract.content).to eq content
100
+ .to raise_error(ActionController::RoutingError)
101
+ contract.reload
102
+ expect(contract.name).to eq name
103
+ expect(contract.title).to eq title
104
+ expect(contract.content).to eq content
105
105
 
106
106
  sign_in @user
107
- expect { post :update, :id => @contract.id,
107
+ expect { post :update, :id => contract.id,
108
108
  :contract => attributes, :use_route => :fine_print }
109
- .to raise_error(FinePrint::SecurityTransgression)
110
- @contract.reload
111
- expect(@contract.name).to eq name
112
- expect(@contract.title).to eq title
113
- expect(@contract.content).to eq content
109
+ .to raise_error(ActionController::RoutingError)
110
+ contract.reload
111
+ expect(contract.name).to eq name
112
+ expect(contract.title).to eq title
113
+ expect(contract.content).to eq content
114
114
  end
115
115
 
116
116
  it 'must update if authorized' do
117
117
  attributes = Hash.new
118
- attributes[:name] = 'some_name'
119
- attributes[:title] = 'Some title'
120
- attributes[:content] = 'Some content'
118
+ attributes[:name] = 'another_name'
119
+ attributes[:title] = 'Another title'
120
+ attributes[:content] = 'Another content'
121
121
 
122
122
  sign_in @admin
123
- put :update, :id => @contract.id, :contract => attributes, :use_route => :fine_print
124
- assert_redirected_to @contract
125
- @contract.reload
126
- expect(@contract.errors).to be_empty
127
- expect(@contract.name).to eq 'some_name'
128
- expect(@contract.title).to eq 'Some title'
129
- expect(@contract.content).to eq 'Some content'
123
+ put :update, :id => contract.id, :contract => attributes, :use_route => :fine_print
124
+ expect(response).to redirect_to contract
125
+ contract.reload
126
+ expect(contract.errors).to be_empty
127
+ expect(contract.name).to eq 'another_name'
128
+ expect(contract.title).to eq 'Another title'
129
+ expect(contract.content).to eq 'Another content'
130
130
  end
131
131
 
132
132
  it "won't destroy unless authorized" do
133
- expect { delete :destroy, :id => @contract.id, :use_route => :fine_print }
134
- .to raise_error(FinePrint::SecurityTransgression)
135
- expect(Contract.find(@contract.id)).to eq @contract
133
+ expect { delete :destroy, :id => contract.id, :use_route => :fine_print }
134
+ .to raise_error(ActionController::RoutingError)
135
+ expect(Contract.find(contract.id)).to eq contract
136
136
 
137
137
  sign_in @user
138
- expect { delete :destroy, :id => @contract.id, :use_route => :fine_print }
139
- .to raise_error(FinePrint::SecurityTransgression)
140
- expect(Contract.find(@contract.id)).to eq @contract
138
+ expect { delete :destroy, :id => contract.id, :use_route => :fine_print }
139
+ .to raise_error(ActionController::RoutingError)
140
+ expect(Contract.find(contract.id)).to eq contract
141
141
  end
142
142
 
143
143
  it 'must destroy if authorized' do
144
144
  sign_in @admin
145
- delete :destroy, :id => @contract.id, :use_route => :fine_print
146
- assert_redirected_to contracts_path
147
- expect(Contract.find_by_id(@contract.id)).to be_nil
145
+ delete :destroy, :id => contract.id, :use_route => :fine_print
146
+ expect(response).to redirect_to contracts_path
147
+ expect(Contract.find_by_id(contract.id)).to be_nil
148
148
  end
149
149
 
150
150
  it "won't publish unless authorized" do
151
- expect(@contract.is_published?).to eq false
152
- expect { put :publish, :id => @contract.id, :use_route => :fine_print }
153
- .to raise_error(FinePrint::SecurityTransgression)
154
- @contract.reload
155
- expect(@contract.is_published?).to eq false
151
+ expect(contract.is_published?).to eq false
152
+ expect { put :publish, :id => contract.id, :use_route => :fine_print }
153
+ .to raise_error(ActionController::RoutingError)
154
+ contract.reload
155
+ expect(contract.is_published?).to eq false
156
156
 
157
157
  sign_in @user
158
- expect { put :publish, :id => @contract.id, :use_route => :fine_print }
159
- .to raise_error(FinePrint::SecurityTransgression)
160
- @contract.reload
161
- expect(@contract.is_published?).to eq false
158
+ expect { put :publish, :id => contract.id, :use_route => :fine_print }
159
+ .to raise_error(ActionController::RoutingError)
160
+ contract.reload
161
+ expect(contract.is_published?).to eq false
162
162
  end
163
163
 
164
164
  it 'must publish if authorized' do
165
- expect(@contract.is_published?).to eq false
165
+ expect(contract.is_published?).to eq false
166
166
  sign_in @admin
167
167
 
168
- put :publish, :id => @contract.id, :use_route => :fine_print
169
- assert_redirected_to contracts_path
170
- @contract.reload
171
- expect(@contract.is_published?).to eq true
168
+ put :publish, :id => contract.id, :use_route => :fine_print
169
+ expect(response).to redirect_to contracts_path
170
+ contract.reload
171
+ expect(contract.is_published?).to eq true
172
172
  end
173
173
 
174
174
  it "won't unpublish unless authorized" do
175
- @contract.publish
176
- expect(@contract.is_published?).to eq true
177
- expect { put :unpublish, :id => @contract.id, :use_route => :fine_print }
178
- .to raise_error(FinePrint::SecurityTransgression)
179
- @contract.reload
180
- expect(@contract.is_published?).to eq true
175
+ contract.publish
176
+ expect(contract.is_published?).to eq true
177
+ expect { put :unpublish, :id => contract.id, :use_route => :fine_print }
178
+ .to raise_error(ActionController::RoutingError)
179
+ contract.reload
180
+ expect(contract.is_published?).to eq true
181
181
 
182
182
  sign_in @user
183
- expect { put :unpublish, :id => @contract.id, :use_route => :fine_print }
184
- .to raise_error(FinePrint::SecurityTransgression)
185
- @contract.reload
186
- expect(@contract.is_published?).to eq true
183
+ expect { put :unpublish, :id => contract.id, :use_route => :fine_print }
184
+ .to raise_error(ActionController::RoutingError)
185
+ contract.reload
186
+ expect(contract.is_published?).to eq true
187
187
  end
188
188
 
189
189
  it 'must unpublish if authorized' do
190
- @contract.publish
191
- expect(@contract.is_published?).to eq true
190
+ contract.publish
191
+ expect(contract.is_published?).to eq true
192
192
 
193
193
  sign_in @admin
194
- put :unpublish, :id => @contract.id, :use_route => :fine_print
195
- assert_redirected_to contracts_path
196
- @contract.reload
197
- expect(@contract.is_published?).to eq false
194
+ put :unpublish, :id => contract.id, :use_route => :fine_print
195
+ expect(response).to redirect_to contracts_path
196
+ contract.reload
197
+ expect(contract.is_published?).to eq false
198
198
  end
199
199
 
200
- it "won't new_version unless authorized" do
201
- @contract.publish
202
- expect(@contract.is_published?).to eq true
200
+ it "won't create new_version unless authorized" do
201
+ contract.publish
202
+ expect(contract.is_published?).to eq true
203
203
 
204
- expect { put :new_version, :id => @contract.id, :use_route => :fine_print }
205
- .to raise_error(FinePrint::SecurityTransgression)
204
+ expect { put :new_version, :id => contract.id, :use_route => :fine_print }
205
+ .to raise_error(ActionController::RoutingError)
206
206
  expect(assigns(:contract)).to be_nil
207
207
 
208
208
  sign_in @user
209
- expect { put :new_version, :id => @contract.id, :use_route => :fine_print }
210
- .to raise_error(FinePrint::SecurityTransgression)
209
+ expect { put :new_version, :id => contract.id, :use_route => :fine_print }
210
+ .to raise_error(ActionController::RoutingError)
211
211
  expect(assigns(:contract)).to be_nil
212
212
  end
213
213
 
214
- it 'must new_version if authorized' do
215
- @contract.publish
216
- expect(@contract.is_published?).to eq true
214
+ it 'must create new_version if authorized' do
215
+ contract.publish
216
+ expect(contract.is_published?).to eq true
217
217
 
218
218
  sign_in @admin
219
- put :new_version, :id => @contract.id, :use_route => :fine_print
220
- assert_response :success
219
+ put :new_version, :id => contract.id, :use_route => :fine_print
220
+ expect(response.status).to eq 200
221
221
  expect(assigns(:contract)).not_to be_nil
222
222
  end
223
223
  end