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.
- checksums.yaml +4 -4
- data/README.md +101 -61
- data/Rakefile +2 -2
- data/app/controllers/fine_print/application_controller.rb +5 -5
- data/app/controllers/fine_print/contracts_controller.rb +15 -12
- data/app/controllers/fine_print/signatures_controller.rb +11 -8
- data/app/models/fine_print/contract.rb +10 -10
- data/app/models/fine_print/signature.rb +9 -8
- data/app/views/fine_print/contracts/_form.html.erb +8 -8
- data/app/views/fine_print/contracts/edit.html.erb +2 -2
- data/app/views/fine_print/contracts/index.html.erb +39 -16
- data/app/views/fine_print/contracts/new.html.erb +3 -1
- data/app/views/fine_print/contracts/new_version.html.erb +7 -4
- data/app/views/fine_print/contracts/show.html.erb +33 -18
- data/app/views/fine_print/signatures/_form.html.erb +7 -4
- data/app/views/fine_print/signatures/index.html.erb +17 -9
- data/app/views/fine_print/signatures/new.html.erb +6 -4
- data/config/initializers/fine_print.rb +39 -36
- data/config/routes.rb +3 -2
- data/db/migrate/0_install_fine_print.rb +8 -8
- data/lib/fine_print.rb +40 -55
- data/lib/fine_print/action_controller/base.rb +118 -0
- data/lib/fine_print/configuration.rb +24 -0
- data/lib/fine_print/engine.rb +10 -6
- data/lib/fine_print/version.rb +1 -1
- data/lib/tasks/fine_print_tasks.rake +4 -2
- data/spec/controllers/contracts_controller_spec.rb +22 -22
- data/spec/controllers/home_controller_spec.rb +1 -1
- data/spec/controllers/signatures_controller_spec.rb +11 -11
- data/spec/dummy/app/views/layouts/application.html.erb +2 -1
- data/spec/dummy/config/initializers/fine_print.rb +2 -1
- data/spec/dummy/config/routes.rb +0 -1
- data/spec/dummy/db/migrate/1_create_dummy_users.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +585 -3119
- data/spec/factories/fine_print/contract.rb +1 -1
- data/spec/factories/fine_print/signature.rb +2 -2
- data/spec/factories/user.rb +1 -1
- data/spec/lib/fine_print/action_controller/base_spec.rb +30 -0
- data/spec/lib/fine_print_spec.rb +14 -11
- data/spec/models/contract_spec.rb +2 -2
- data/spec/models/signature_spec.rb +1 -1
- metadata +6 -5
- data/lib/fine_print/controller_includes.rb +0 -93
- data/spec/lib/fine_print/controller_includes_spec.rb +0 -25
data/config/routes.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
FinePrint::Engine.routes.draw do
|
2
|
-
root :
|
2
|
+
root to: 'home#index'
|
3
3
|
|
4
4
|
resources :contracts do
|
5
|
-
resources :signatures, :
|
5
|
+
resources :signatures, only: [:index, :new, :create, :destroy],
|
6
|
+
shallow: true
|
6
7
|
|
7
8
|
member do
|
8
9
|
post :new_version
|
@@ -1,26 +1,26 @@
|
|
1
1
|
class InstallFinePrint < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :fine_print_contracts do |t|
|
4
|
-
t.string :name, :
|
4
|
+
t.string :name, null: false
|
5
5
|
t.integer :version
|
6
|
-
t.string :title, :
|
7
|
-
t.text :content, :
|
6
|
+
t.string :title, null: false
|
7
|
+
t.text :content, null: false
|
8
8
|
|
9
9
|
t.timestamps
|
10
10
|
end
|
11
11
|
|
12
|
-
add_index :fine_print_contracts, [:name, :version], :
|
12
|
+
add_index :fine_print_contracts, [:name, :version], unique: true
|
13
13
|
|
14
14
|
create_table :fine_print_signatures do |t|
|
15
|
-
t.belongs_to :contract, :
|
16
|
-
t.belongs_to :user, :
|
15
|
+
t.belongs_to :contract, null: false
|
16
|
+
t.belongs_to :user, polymorphic: true, null: false
|
17
17
|
|
18
18
|
t.timestamps
|
19
19
|
end
|
20
20
|
|
21
21
|
add_index :fine_print_signatures, [:user_id, :user_type, :contract_id],
|
22
|
-
:
|
23
|
-
:
|
22
|
+
name: 'index_fine_print_s_on_u_id_and_u_type_and_c_id',
|
23
|
+
unique: true
|
24
24
|
add_index :fine_print_signatures, :contract_id
|
25
25
|
end
|
26
26
|
end
|
data/lib/fine_print.rb
CHANGED
@@ -1,42 +1,27 @@
|
|
1
|
+
require 'fine_print/configuration'
|
1
2
|
require 'fine_print/engine'
|
2
|
-
require 'fine_print/controller_includes'
|
3
3
|
|
4
4
|
module FinePrint
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
ENGINE_OPTIONS = [
|
9
|
-
:current_user_proc,
|
10
|
-
:can_manage_proc,
|
11
|
-
:can_sign_proc,
|
12
|
-
:layout,
|
13
|
-
:helpers
|
14
|
-
]
|
15
|
-
|
16
|
-
# Can be set in initializer or passed as an argument
|
17
|
-
# to FinePrint controller methods
|
18
|
-
CONTROLLER_OPTIONS = [
|
19
|
-
:must_sign_proc
|
20
|
-
]
|
21
|
-
|
22
|
-
(ENGINE_OPTIONS + CONTROLLER_OPTIONS).each do |option|
|
23
|
-
mattr_accessor option
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@config ||= Configuration.new
|
24
8
|
end
|
25
|
-
|
9
|
+
|
26
10
|
def self.configure
|
27
|
-
yield
|
11
|
+
yield config
|
28
12
|
end
|
29
13
|
|
30
14
|
# Gets a contract, given either the contract object, ID or name
|
31
|
-
# If given a name,
|
32
|
-
# - contract - can be a Contract object, its ID, or its name
|
15
|
+
# If given a name, returns the latest published version of that contract
|
16
|
+
# - contract - can be a Contract object, its ID, or its name
|
33
17
|
def self.get_contract(reference)
|
34
18
|
return reference if reference.is_a? Contract
|
35
19
|
num = Integer(reference) rescue nil
|
36
20
|
return Contract.find(num) if num
|
37
|
-
contract = Contract.where(:
|
21
|
+
contract = Contract.where(name: reference.to_s).published.first
|
38
22
|
return contract if contract
|
39
|
-
raise ActiveRecord::RecordNotFound,
|
23
|
+
raise ActiveRecord::RecordNotFound,
|
24
|
+
"Couldn't find Contract with 'name'=#{reference.to_s}"
|
40
25
|
end
|
41
26
|
|
42
27
|
# Records that the given user has signed the given contract
|
@@ -55,55 +40,55 @@ module FinePrint
|
|
55
40
|
# - user - the user in question
|
56
41
|
# - contract - can be a Contract object, its ID, or its name (String/Symbol)
|
57
42
|
def self.signed_contract?(user, contract)
|
43
|
+
return false if user.nil?
|
44
|
+
|
58
45
|
contract = get_contract(contract)
|
59
46
|
|
60
|
-
contract.signatures.where(:
|
61
|
-
:
|
47
|
+
contract.signatures.where(user_id: user.id,
|
48
|
+
user_type: user.class.name).exists?
|
62
49
|
end
|
63
50
|
|
64
51
|
# Returns true iff the given user has signed any version of the given contract
|
65
52
|
# - user - the user in question
|
66
53
|
# - contract - can be a Contract object, its ID, or its name (String/Symbol)
|
67
54
|
def self.signed_any_version_of_contract?(user, contract)
|
55
|
+
return false if user.nil?
|
56
|
+
|
68
57
|
contract = get_contract(contract)
|
69
58
|
|
70
|
-
contract.same_name.
|
71
|
-
|
72
|
-
|
73
|
-
end
|
59
|
+
contract.same_name.joins(:signatures).where(
|
60
|
+
signatures: { user_id: user.id, user_type: user.class.name }
|
61
|
+
).exists?
|
74
62
|
end
|
75
63
|
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
names = contract_names.flatten
|
80
|
-
Contract.latest.where(:name => names).pluck(:id)
|
64
|
+
# Returns all the latest published contracts that match the given conditions.
|
65
|
+
def self.latest_published_contracts(conditions = {})
|
66
|
+
Contract.published.latest.where(conditions)
|
81
67
|
end
|
82
68
|
|
83
|
-
# Returns
|
69
|
+
# Returns all contracts matching the given conditions
|
84
70
|
# whose latest published version the user has signed.
|
85
71
|
# - user - the user in question
|
86
|
-
# -
|
87
|
-
# If no
|
88
|
-
def self.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
72
|
+
# - conditions - filters the list of contracts to check
|
73
|
+
# If no conditions are provided, all latest contracts are checked.
|
74
|
+
def self.signed_contracts_for(user, conditions = {})
|
75
|
+
return [] if user.nil?
|
76
|
+
|
77
|
+
contracts = latest_published_contracts(conditions)
|
78
|
+
contracts.joins(:signatures).where(
|
79
|
+
signatures: { user_id: user.id, user_type: user.class.name }
|
80
|
+
)
|
95
81
|
end
|
96
82
|
|
97
|
-
# Returns
|
83
|
+
# Returns all contracts matching the given conditions
|
98
84
|
# whose latest published version the user has not signed.
|
99
85
|
# - user - the user in question
|
100
|
-
# -
|
101
|
-
# If no
|
102
|
-
def self.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
ids - get_signed_contract_ids(user, ids)
|
86
|
+
# - conditions - filters the list of contracts to check
|
87
|
+
# If no conditions are provided, all latest contracts are checked.
|
88
|
+
def self.unsigned_contracts_for(user, conditions = {})
|
89
|
+
contracts = latest_published_contracts(conditions)
|
90
|
+
signed_contracts = signed_contracts_for(user, conditions)
|
91
|
+
contracts - signed_contracts
|
107
92
|
end
|
108
93
|
|
109
94
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module FinePrint
|
2
|
+
module ActionController
|
3
|
+
module Base
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Accepts an array of contract names and an options hash
|
10
|
+
# Checks if the current user has signed the given contracts
|
11
|
+
# and calls fine_print_redirect if not
|
12
|
+
# Options relevant to FinePrint are passed to fine_print_redirect
|
13
|
+
# If no names are given, requires all contracts
|
14
|
+
def fine_print_require(*names)
|
15
|
+
options = names.last.is_a?(Hash) ? names.pop : {}
|
16
|
+
fp_opts = options.slice(*FinePrint::Configuration::CONTROLLER_OPTIONS)
|
17
|
+
|
18
|
+
# Convert names to an array of Strings
|
19
|
+
contract_names = names.flatten.collect{|c| c.to_s}
|
20
|
+
contract_names = ['all'] if contract_names.empty?
|
21
|
+
contract_names = FinePrint::Contract.all.to_a.collect{|c| c.name}
|
22
|
+
.uniq if contract_names.include?('all')
|
23
|
+
|
24
|
+
user = instance_exec &FinePrint.config.current_user_proc
|
25
|
+
|
26
|
+
can_sign = instance_exec(user, &FinePrint.config.authenticate_user_proc)
|
27
|
+
|
28
|
+
return if !can_sign || performed?
|
29
|
+
|
30
|
+
unsigned_contracts = FinePrint.unsigned_contracts_for(
|
31
|
+
user, name: contract_names
|
32
|
+
)
|
33
|
+
|
34
|
+
# Return quietly if all contracts signed
|
35
|
+
return if unsigned_contracts.blank?
|
36
|
+
|
37
|
+
fine_print_redirect(user, unsigned_contracts, fp_opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Accepts a user, an array of contract ids to be signed and an options hash
|
41
|
+
# Calls the `redirect_to_contracts_proc` with the given parameters
|
42
|
+
def fine_print_redirect(user, *contracts)
|
43
|
+
options = contracts.last.is_a?(Hash) ? contracts.pop : {}
|
44
|
+
contracts = contracts.flatten
|
45
|
+
|
46
|
+
blk = options[:redirect_to_contracts_proc] || \
|
47
|
+
FinePrint.config.redirect_to_contracts_proc
|
48
|
+
|
49
|
+
# Use action_interceptor to save the current url
|
50
|
+
store_url key: :fine_print_return_to
|
51
|
+
|
52
|
+
instance_exec user, contracts, &blk
|
53
|
+
end
|
54
|
+
|
55
|
+
# Accepts no arguments
|
56
|
+
# Redirects the user back to the url they were at before
|
57
|
+
# `fine_print_redirect` redirected them
|
58
|
+
def fine_print_return
|
59
|
+
redirect_back key: :fine_print_return_to
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def fine_print_skipped_contract_names
|
65
|
+
@fine_print_skipped_contract_names ||= []
|
66
|
+
end
|
67
|
+
|
68
|
+
module ClassMethods
|
69
|
+
# Accepts an array of contract names and an options hash
|
70
|
+
# Adds a before_filter to the current controller that will check if the
|
71
|
+
# current user has signed the given contracts and call the sign_proc if appropriate
|
72
|
+
# Options relevant to FinePrint are passed to fine_print_sign, while
|
73
|
+
# other options are passed to the before_filter
|
74
|
+
def fine_print_require(*names)
|
75
|
+
options = names.last.is_a?(Hash) ? names.pop : {}
|
76
|
+
f_opts = options.except(*FinePrint::Configuration::CONTROLLER_OPTIONS)
|
77
|
+
|
78
|
+
# Convert names to an array of Strings
|
79
|
+
contract_names = names.flatten.collect{|c| c.to_s}
|
80
|
+
contract_names = ['all'] if contract_names.empty?
|
81
|
+
|
82
|
+
class_exec do
|
83
|
+
before_filter(f_opts) do |controller|
|
84
|
+
skipped_contract_names = fine_print_skipped_contract_names
|
85
|
+
next if skipped_contract_names.include?('all')
|
86
|
+
contract_names = FinePrint::Contract.all.to_a.collect{|c| c.name}
|
87
|
+
.uniq if contract_names.include?('all')
|
88
|
+
unskipped_contract_names = contract_names - skipped_contract_names
|
89
|
+
controller.fine_print_require(unskipped_contract_names, options) \
|
90
|
+
unless unskipped_contract_names.empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Accepts an array of contract names and an options hash
|
96
|
+
# Excludes the given contracts from the `fine_print_require`
|
97
|
+
# check for this controller and subclasses
|
98
|
+
# Options are passed to prepend_before_filter
|
99
|
+
def fine_print_skip(*names)
|
100
|
+
options = names.last.is_a?(Hash) ? names.pop : {}
|
101
|
+
|
102
|
+
# Convert names to an array of Strings
|
103
|
+
contract_names = names.flatten.collect{|c| c.to_s}
|
104
|
+
contract_names = ['all'] if contract_names.empty?
|
105
|
+
|
106
|
+
class_exec do
|
107
|
+
prepend_before_filter(options) do |controller|
|
108
|
+
controller.fine_print_skipped_contract_names.push(*contract_names)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
::ActionController::Base.send :include, FinePrint::ActionController::Base
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FinePrint
|
2
|
+
class Configuration
|
3
|
+
# Attributes
|
4
|
+
|
5
|
+
# Can be set in initializer only
|
6
|
+
ENGINE_OPTIONS = [
|
7
|
+
:helpers,
|
8
|
+
:layout,
|
9
|
+
:authenticate_user_proc,
|
10
|
+
:authenticate_manager_proc,
|
11
|
+
:current_user_proc
|
12
|
+
]
|
13
|
+
|
14
|
+
# Can be set in initializer or passed as an argument
|
15
|
+
# to FinePrint controller methods
|
16
|
+
CONTROLLER_OPTIONS = [
|
17
|
+
:redirect_to_contracts_proc
|
18
|
+
]
|
19
|
+
|
20
|
+
(ENGINE_OPTIONS + CONTROLLER_OPTIONS).each do |option|
|
21
|
+
attr_accessor option
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fine_print/engine.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
require 'action_interceptor'
|
2
2
|
require 'squeel'
|
3
|
+
require 'fine_print/action_controller/base'
|
3
4
|
|
4
5
|
module FinePrint
|
5
6
|
class Engine < ::Rails::Engine
|
6
7
|
isolate_namespace FinePrint
|
7
8
|
|
8
|
-
initializer "fine_print.factories",
|
9
|
-
|
10
|
-
|
9
|
+
initializer "fine_print.factories",
|
10
|
+
after: "factory_girl.set_factory_paths" do
|
11
|
+
FactoryGirl.definition_file_paths << File.join(
|
12
|
+
root, 'spec', 'factories', 'fine_print'
|
13
|
+
) if defined?(FactoryGirl)
|
11
14
|
end
|
12
15
|
|
13
16
|
# http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
|
14
17
|
config.generators do |g|
|
15
|
-
g.test_framework :rspec, :
|
16
|
-
g.fixture_replacement :factory_girl, :
|
18
|
+
g.test_framework :rspec, fixture: false
|
19
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
17
20
|
g.assets false
|
18
21
|
g.helper false
|
19
22
|
end
|
20
23
|
|
21
24
|
# Load subfolders of config/locales as well
|
22
|
-
config.i18n.load_path +=
|
25
|
+
config.i18n.load_path += \
|
26
|
+
Dir[root.join('config', 'locales', '**', '*.{rb,yml}')]
|
23
27
|
end
|
24
28
|
end
|
data/lib/fine_print/version.rb
CHANGED
@@ -10,7 +10,7 @@ namespace :fine_print do
|
|
10
10
|
if File.exists?(File.expand_path(File.basename(file), 'config/initializers'))
|
11
11
|
print "NOTE: Initializer #{File.basename(file)} from fine_print has been skipped. Initializer with the same name already exists.\n"
|
12
12
|
else
|
13
|
-
cp file, 'config/initializers', :
|
13
|
+
cp file, 'config/initializers', verbose: false
|
14
14
|
print "Copied initializer #{File.basename(file)} from fine_print\n"
|
15
15
|
end
|
16
16
|
end
|
@@ -22,7 +22,9 @@ namespace :fine_print do
|
|
22
22
|
name = File.basename(path)
|
23
23
|
desc "Copy #{name} from fine_print to application"
|
24
24
|
task name.to_sym do
|
25
|
-
cp_r File.expand_path("../../../app/#{path}/fine_print", __FILE__),
|
25
|
+
cp_r File.expand_path("../../../app/#{path}/fine_print", __FILE__),
|
26
|
+
"app/#{path}",
|
27
|
+
verbose: false
|
26
28
|
print "Copied #{name} from fine_print\n"
|
27
29
|
end
|
28
30
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module FinePrint
|
4
|
-
describe ContractsController, :
|
4
|
+
describe ContractsController, type: :controller do
|
5
5
|
routes { FinePrint::Engine.routes }
|
6
6
|
|
7
7
|
before(:each) do
|
@@ -46,12 +46,12 @@ module FinePrint
|
|
46
46
|
attributes[:title] = 'Some title'
|
47
47
|
attributes[:content] = 'Some content'
|
48
48
|
|
49
|
-
post :create, :
|
49
|
+
post :create, contract: :attributes
|
50
50
|
expect(response.status).to eq 403
|
51
51
|
expect(assigns(:contract)).to be_nil
|
52
52
|
|
53
53
|
sign_in @user
|
54
|
-
post :create, :
|
54
|
+
post :create, contract: :attributes
|
55
55
|
expect(response.status).to eq 403
|
56
56
|
expect(assigns(:contract)).to be_nil
|
57
57
|
end
|
@@ -63,7 +63,7 @@ module FinePrint
|
|
63
63
|
attributes[:title] = 'Some title'
|
64
64
|
attributes[:content] = 'Some content'
|
65
65
|
|
66
|
-
post :create, :
|
66
|
+
post :create, contract: attributes
|
67
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'
|
@@ -72,17 +72,17 @@ module FinePrint
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "won't edit unless authorized" do
|
75
|
-
get :edit, :
|
75
|
+
get :edit, id: contract.id
|
76
76
|
expect(response.status).to eq 403
|
77
77
|
|
78
78
|
sign_in @user
|
79
|
-
get :edit, :
|
79
|
+
get :edit, id: contract.id
|
80
80
|
expect(response.status).to eq 403
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'must edit if authorized' do
|
84
84
|
sign_in @admin
|
85
|
-
get :edit, :
|
85
|
+
get :edit, id: contract.id
|
86
86
|
expect(response.status).to eq 200
|
87
87
|
end
|
88
88
|
|
@@ -95,7 +95,7 @@ module FinePrint
|
|
95
95
|
title = contract.title
|
96
96
|
content = contract.content
|
97
97
|
|
98
|
-
put :update, :
|
98
|
+
put :update, id: contract.id, contract: attributes
|
99
99
|
expect(response.status).to eq 403
|
100
100
|
contract.reload
|
101
101
|
expect(contract.name).to eq name
|
@@ -103,7 +103,7 @@ module FinePrint
|
|
103
103
|
expect(contract.content).to eq content
|
104
104
|
|
105
105
|
sign_in @user
|
106
|
-
put :update, :
|
106
|
+
put :update, id: contract.id, contract: attributes
|
107
107
|
expect(response.status).to eq 403
|
108
108
|
contract.reload
|
109
109
|
expect(contract.name).to eq name
|
@@ -118,7 +118,7 @@ module FinePrint
|
|
118
118
|
attributes[:content] = 'Another content'
|
119
119
|
|
120
120
|
sign_in @admin
|
121
|
-
put :update, :
|
121
|
+
put :update, id: contract.id, contract: attributes
|
122
122
|
expect(response).to redirect_to contract
|
123
123
|
contract.reload
|
124
124
|
expect(contract.errors).to be_empty
|
@@ -128,32 +128,32 @@ module FinePrint
|
|
128
128
|
end
|
129
129
|
|
130
130
|
it "won't destroy unless authorized" do
|
131
|
-
delete :destroy, :
|
131
|
+
delete :destroy, id: contract.id
|
132
132
|
expect(response.status).to eq 403
|
133
133
|
expect(Contract.find(contract.id)).to eq contract
|
134
134
|
|
135
135
|
sign_in @user
|
136
|
-
delete :destroy, :
|
136
|
+
delete :destroy, id: contract.id
|
137
137
|
expect(response.status).to eq 403
|
138
138
|
expect(Contract.find(contract.id)).to eq contract
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'must destroy if authorized' do
|
142
142
|
sign_in @admin
|
143
|
-
delete :destroy, :
|
143
|
+
delete :destroy, id: contract.id
|
144
144
|
expect(response).to redirect_to contracts_path
|
145
145
|
expect(Contract.find_by_id(contract.id)).to be_nil
|
146
146
|
end
|
147
147
|
|
148
148
|
it "won't publish unless authorized" do
|
149
149
|
expect(contract.is_published?).to eq false
|
150
|
-
put :publish, :
|
150
|
+
put :publish, id: contract.id
|
151
151
|
expect(response.status).to eq 403
|
152
152
|
contract.reload
|
153
153
|
expect(contract.is_published?).to eq false
|
154
154
|
|
155
155
|
sign_in @user
|
156
|
-
put :publish, :
|
156
|
+
put :publish, id: contract.id
|
157
157
|
expect(response.status).to eq 403
|
158
158
|
contract.reload
|
159
159
|
expect(contract.is_published?).to eq false
|
@@ -163,7 +163,7 @@ module FinePrint
|
|
163
163
|
expect(contract.is_published?).to eq false
|
164
164
|
sign_in @admin
|
165
165
|
|
166
|
-
put :publish, :
|
166
|
+
put :publish, id: contract.id
|
167
167
|
expect(response).to redirect_to contracts_path
|
168
168
|
contract.reload
|
169
169
|
expect(contract.is_published?).to eq true
|
@@ -172,13 +172,13 @@ module FinePrint
|
|
172
172
|
it "won't unpublish unless authorized" do
|
173
173
|
contract.publish
|
174
174
|
expect(contract.is_published?).to eq true
|
175
|
-
put :unpublish, :
|
175
|
+
put :unpublish, id: contract.id
|
176
176
|
expect(response.status).to eq 403
|
177
177
|
contract.reload
|
178
178
|
expect(contract.is_published?).to eq true
|
179
179
|
|
180
180
|
sign_in @user
|
181
|
-
put :unpublish, :
|
181
|
+
put :unpublish, id: contract.id
|
182
182
|
expect(response.status).to eq 403
|
183
183
|
contract.reload
|
184
184
|
expect(contract.is_published?).to eq true
|
@@ -189,7 +189,7 @@ module FinePrint
|
|
189
189
|
expect(contract.is_published?).to eq true
|
190
190
|
|
191
191
|
sign_in @admin
|
192
|
-
put :unpublish, :
|
192
|
+
put :unpublish, id: contract.id
|
193
193
|
expect(response).to redirect_to contracts_path
|
194
194
|
contract.reload
|
195
195
|
expect(contract.is_published?).to eq false
|
@@ -199,12 +199,12 @@ module FinePrint
|
|
199
199
|
contract.publish
|
200
200
|
expect(contract.is_published?).to eq true
|
201
201
|
|
202
|
-
post :new_version, :
|
202
|
+
post :new_version, id: contract.id
|
203
203
|
expect(response.status).to eq 403
|
204
204
|
expect(assigns(:contract)).to be_nil
|
205
205
|
|
206
206
|
sign_in @user
|
207
|
-
post :new_version, :
|
207
|
+
post :new_version, id: contract.id
|
208
208
|
expect(response.status).to eq 403
|
209
209
|
expect(assigns(:contract)).to be_nil
|
210
210
|
end
|
@@ -214,7 +214,7 @@ module FinePrint
|
|
214
214
|
expect(contract.is_published?).to eq true
|
215
215
|
|
216
216
|
sign_in @admin
|
217
|
-
post :new_version, :
|
217
|
+
post :new_version, id: contract.id
|
218
218
|
expect(response.status).to eq 200
|
219
219
|
expect(assigns(:contract)).not_to be_nil
|
220
220
|
end
|