fine_print 0.1.1 → 1.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.
- checksums.yaml +7 -0
- data/README.md +74 -45
- data/Rakefile +9 -9
- data/app/assets/javascripts/application.js~ +16 -0
- data/app/assets/javascripts/fine_print/application.js +8 -2
- data/app/controllers/fine_print/application_controller.rb +9 -7
- data/app/controllers/fine_print/application_controller.rb~ +9 -7
- data/app/controllers/fine_print/contracts_controller.rb +79 -0
- data/app/controllers/fine_print/contracts_controller.rb~ +79 -0
- data/app/controllers/fine_print/home_controller.rb +1 -11
- data/app/controllers/fine_print/home_controller.rb~ +2 -11
- data/app/controllers/fine_print/signatures_controller.rb +14 -0
- data/app/controllers/fine_print/signatures_controller.rb~ +14 -0
- data/app/helpers/fine_print/application_helper.rb +7 -0
- data/app/helpers/fine_print/application_helper.rb~ +7 -0
- data/app/helpers/fine_print/contracts_helper.rb~ +7 -0
- data/app/models/fine_print/contract.rb +96 -0
- data/app/models/fine_print/contract.rb~ +100 -0
- data/app/models/fine_print/signature.rb +25 -0
- data/app/models/fine_print/signature.rb~ +25 -0
- data/app/views/fine_print/contracts/_form.html.erb +35 -0
- data/app/views/fine_print/contracts/_form.html.erb~ +35 -0
- data/app/views/fine_print/contracts/edit.html.erb +10 -0
- data/app/views/fine_print/contracts/index.html.erb +43 -0
- data/app/views/fine_print/contracts/index.html.erb~ +43 -0
- data/app/views/fine_print/contracts/new.html.erb +9 -0
- data/app/views/fine_print/contracts/new_version.html.erb +9 -0
- data/app/views/fine_print/contracts/show.html.erb +33 -0
- data/app/views/fine_print/contracts/show.html.erb~ +35 -0
- data/app/views/fine_print/home/index.html.erb +15 -6
- data/app/views/fine_print/home/index.html.erb~ +12 -4
- data/app/views/fine_print/signatures/index.html.erb +36 -0
- data/app/views/fine_print/signatures/index.html.erb~ +32 -0
- data/app/views/layouts/fine_print/application.html.erb +6 -0
- data/app/views/layouts/fine_print/application.html.erb~ +20 -0
- data/config/initializers/fine_print.rb +27 -44
- data/config/initializers/fine_print.rb~ +23 -40
- data/config/routes.rb +9 -3
- data/config/routes.rb~ +9 -4
- data/db/migrate/0_install_fine_print.rb +26 -0
- data/db/migrate/0_install_fine_print.rb~ +26 -0
- data/lib/fine_print/controller_additions.rb +69 -0
- data/lib/fine_print/controller_additions.rb~ +69 -0
- data/lib/fine_print/engine.rb +8 -0
- data/lib/fine_print/security_transgression.rb +1 -2
- data/lib/fine_print/utilities.rb~ +26 -0
- data/lib/fine_print/version.rb +1 -1
- data/lib/fine_print.rb +89 -42
- data/lib/fine_print.rb~ +89 -41
- data/lib/tasks/fine_print_tasks.rake +11 -8
- data/spec/controllers/contracts_controller_spec.rb +222 -0
- data/spec/controllers/contracts_controller_spec.rb~ +224 -0
- data/spec/controllers/home_controller_spec.rb +25 -0
- data/spec/controllers/home_controller_spec.rb~ +25 -0
- data/spec/controllers/signatures_controller_spec.rb +46 -0
- data/spec/controllers/signatures_controller_spec.rb~ +46 -0
- data/spec/dummy/README.md +1 -1
- data/spec/dummy/app/controllers/dummy_models_controller.rb +2 -0
- data/spec/dummy/app/controllers/dummy_models_controller.rb~ +29 -0
- data/spec/dummy/app/helpers/application_helper.rb +13 -0
- data/spec/dummy/app/models/dummy_user.rb +3 -0
- data/spec/dummy/app/models/dummy_user.rb~ +4 -0
- data/spec/dummy/app/models/user.rb~ +78 -0
- data/spec/dummy/config/application.rb +2 -2
- data/spec/dummy/config/application.rb~ +60 -0
- data/spec/dummy/config/initializers/fine_print.rb +36 -0
- data/spec/dummy/config/initializers/fine_print.rb~ +36 -0
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb~ +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb~ +14 -0
- data/spec/dummy/config/routes.rb +1 -2
- data/spec/dummy/config/routes.rb~ +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/1_create_dummy_users.rb +9 -0
- data/spec/dummy/db/migrate/1_create_dummy_users.rb~ +8 -0
- data/spec/dummy/db/schema.rb +20 -12
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1635 -0
- data/spec/dummy/log/test.log +46188 -0
- data/spec/factories/contract.rb +25 -0
- data/spec/factories/contract.rb~ +26 -0
- data/spec/factories/dummy_user.rb +4 -0
- data/spec/factories/dummy_user.rb~ +6 -0
- data/spec/factories/signature.rb +6 -0
- data/spec/factories/signature.rb~ +8 -0
- data/spec/factories/user.rb~ +6 -0
- data/spec/fine_print_spec.rb~ +15 -4
- data/spec/lib/fine_print/controller_additions_spec.rb +20 -0
- data/spec/lib/fine_print/controller_additions_spec.rb~ +20 -0
- data/spec/lib/fine_print_spec.rb +47 -0
- data/spec/lib/fine_print_spec.rb~ +47 -0
- data/spec/models/contract_spec.rb +79 -0
- data/spec/models/contract_spec.rb~ +80 -0
- data/spec/models/signature_spec.rb +28 -0
- data/spec/models/signature_spec.rb~ +28 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/spec_helper.rb~ +32 -0
- data/spec/test_helper.rb~ +15 -0
- metadata +153 -91
- data/app/assets/javascripts/fine_print/agreements.js +0 -19
- data/app/assets/javascripts/fine_print/agreements.js~ +0 -19
- data/app/assets/javascripts/fine_print/application.js~ +0 -5
- data/app/assets/javascripts/fine_print/dialog.js +0 -2
- data/app/assets/javascripts/fine_print/dialog.js~ +0 -2
- data/app/assets/javascripts/fine_print/user_agreements.js +0 -20
- data/app/assets/javascripts/fine_print/user_agreements.js~ +0 -20
- data/app/assets/stylesheets/fine_print/agreements.css +0 -11
- data/app/assets/stylesheets/fine_print/agreements.css~ +0 -11
- data/app/assets/stylesheets/fine_print/application.css~ +0 -60
- data/app/assets/stylesheets/fine_print/user_agreements.css~ +0 -3
- data/app/assets/stylesheets/scaffold.css~ +0 -56
- data/app/controllers/fine_print/agreements_controller.rb +0 -114
- data/app/controllers/fine_print/agreements_controller.rb~ +0 -113
- data/app/controllers/fine_print/user_agreements_controller.rb +0 -63
- data/app/controllers/fine_print/user_agreements_controller.rb~ +0 -63
- data/app/models/fine_print/agreement.rb +0 -50
- data/app/models/fine_print/agreement.rb~ +0 -50
- data/app/models/fine_print/user_agreement.rb +0 -19
- data/app/models/fine_print/user_agreement.rb~ +0 -21
- data/app/views/fine_print/agreements/_agreement.html.erb +0 -77
- data/app/views/fine_print/agreements/_agreement.html.erb~ +0 -77
- data/app/views/fine_print/agreements/_dialog.html.erb +0 -27
- data/app/views/fine_print/agreements/_dialog.html.erb~ +0 -27
- data/app/views/fine_print/agreements/_form.html.erb +0 -51
- data/app/views/fine_print/agreements/_form.html.erb~ +0 -51
- data/app/views/fine_print/agreements/edit.html.erb +0 -8
- data/app/views/fine_print/agreements/edit.html.erb~ +0 -8
- data/app/views/fine_print/agreements/index.html.erb +0 -32
- data/app/views/fine_print/agreements/index.html.erb~ +0 -32
- data/app/views/fine_print/agreements/new.html.erb +0 -7
- data/app/views/fine_print/agreements/new.html.erb~ +0 -7
- data/app/views/fine_print/agreements/new_version.html.erb +0 -7
- data/app/views/fine_print/agreements/new_version.html.erb~ +0 -7
- data/app/views/fine_print/agreements/show.html.erb +0 -15
- data/app/views/fine_print/agreements/show.html.erb~ +0 -14
- data/app/views/fine_print/user_agreements/cancel.js.erb +0 -1
- data/app/views/fine_print/user_agreements/cancel.js.erb~ +0 -2
- data/app/views/fine_print/user_agreements/create.js.erb +0 -2
- data/app/views/fine_print/user_agreements/create.js.erb~ +0 -2
- data/app/views/fine_print/user_agreements/index.html.erb +0 -25
- data/app/views/fine_print/user_agreements/index.html.erb~ +0 -25
- data/db/migrate/0_create_fine_print_agreements.rb~ +0 -22
- data/db/migrate/0_install.rb +0 -28
- data/db/migrate/0_install.rb~ +0 -28
- data/lib/fine_print/agreements_helper.rb +0 -13
- data/lib/fine_print/agreements_helper.rb~ +0 -11
- data/lib/fine_print/fine_print_agreement.rb +0 -26
- data/lib/fine_print/fine_print_agreement.rb~ +0 -26
- data/lib/fine_print/require_agreement.rb~ +0 -22
- data/lib/fine_print/security_transgression.rb~ +0 -3
- data/lib/fine_print/version.rb~ +0 -3
- data/lib/tasks/fine_print_tasks.rake~ +0 -42
- data/spec/dummy/README.md~ +0 -3
- data/spec/fine_print_spec.rb +0 -7
- data/spec/minitest_helper.rb +0 -12
data/lib/fine_print.rb~
CHANGED
@@ -1,68 +1,116 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'fine_print/engine'
|
2
|
+
require 'fine_print/security_transgression'
|
3
|
+
require 'fine_print/controller_additions'
|
3
4
|
|
4
5
|
module FinePrint
|
5
|
-
ASSET_FILES = %w(dialog.js)
|
6
|
-
|
7
6
|
# Attributes
|
8
7
|
|
9
8
|
# Can be set in initializer only
|
10
9
|
ENGINE_OPTIONS = [
|
11
10
|
:current_user_method,
|
12
11
|
:user_admin_proc,
|
13
|
-
:
|
14
|
-
:
|
12
|
+
:user_signed_in_proc,
|
13
|
+
:pose_contracts_path,
|
14
|
+
:redirect_path
|
15
15
|
]
|
16
16
|
|
17
|
-
# Can be set in initializer or passed as an option to
|
18
|
-
|
19
|
-
:
|
20
|
-
:accept_path,
|
21
|
-
:cancel_path,
|
22
|
-
:use_referers,
|
23
|
-
:use_modal_dialogs
|
17
|
+
# Can be set in initializer or passed as an option to fine_print_get_signatures
|
18
|
+
SIGNATURE_OPTIONS = [
|
19
|
+
:pose_contracts_path
|
24
20
|
]
|
25
21
|
|
26
|
-
(ENGINE_OPTIONS +
|
22
|
+
(ENGINE_OPTIONS + SIGNATURE_OPTIONS).each do |option|
|
27
23
|
mattr_accessor option
|
28
24
|
end
|
29
|
-
|
30
|
-
ActiveSupport.on_load(:before_initialize) do
|
31
|
-
Rails.configuration.assets.precompile += ASSET_FILES
|
32
|
-
end
|
33
25
|
|
34
26
|
def self.configure
|
35
27
|
yield self
|
36
28
|
end
|
37
29
|
|
38
|
-
|
39
|
-
|
30
|
+
# Gets a contract given either the contract's object, ID or name
|
31
|
+
# If given a name, it returns the latest published version of that contract
|
32
|
+
#
|
33
|
+
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
|
41
|
+
Contract.where(:name => ref).published.first
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns an array of names for the contracts whose latest published
|
46
|
+
# version the given user has not signed.
|
47
|
+
# - names -- an array of contract names
|
48
|
+
# - user -- the user in question
|
49
|
+
#
|
50
|
+
def self.get_unsigned_contract_names(names, user)
|
51
|
+
raise_unless_signed_in(user)
|
52
|
+
return [] if names.blank?
|
53
|
+
names_array = names.is_a?(Array) ? names.collect{|name| name.to_s} : [names.to_s]
|
54
|
+
|
55
|
+
signed_contracts = Contract
|
56
|
+
.joins(:signatures)
|
57
|
+
.where({:name => names_array,
|
58
|
+
:fine_print_signatures => {:user_id => user.id,
|
59
|
+
:user_type => user.class.name}}).latest
|
60
|
+
signed_contract_names = signed_contracts.collect{|c| c.name}
|
61
|
+
|
62
|
+
return names - signed_contract_names
|
40
63
|
end
|
41
64
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
controller.session[:fine_print_request_url] = controller.request.url
|
54
|
-
controller.session[:fine_print_request_ref] = controller.request.referer
|
55
|
-
end
|
56
|
-
controller.redirect_to controller.fine_print.agreement_path(agreement),
|
57
|
-
:notice => get_option(options, :agreement_notice)
|
58
|
-
end
|
65
|
+
# Records that the given user has signed the given contract; the contract
|
66
|
+
# can be a Contract object, a contract ID, or a contract name (string)
|
67
|
+
#
|
68
|
+
def self.sign_contract(contract, user)
|
69
|
+
raise_unless_signed_in(user)
|
70
|
+
contract = get_contract(contract)
|
71
|
+
raise IllegalState, 'Contract not found' if contract.nil?
|
72
|
+
|
73
|
+
sig = Signature.create do |signature|
|
74
|
+
signature.user = user
|
75
|
+
signature.contract = contract
|
59
76
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns true iff the given user has signed the given contract; the contract
|
80
|
+
# can be a Contract object, a contract ID, or a contract name (string)
|
81
|
+
#
|
82
|
+
def self.signed_contract?(contract, user)
|
83
|
+
raise_unless_signed_in(user)
|
84
|
+
contract = get_contract(contract)
|
85
|
+
|
86
|
+
!contract.signatures.where(:user_id => user.id,
|
87
|
+
:user_type => user.class.name).first.nil?
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns true iff the given user has signed any version of the given contract.
|
91
|
+
# - contract -- can be a Contract object, its ID, or its name as a String or Symbol
|
92
|
+
def self.signed_any_contract_version?(contract, user)
|
93
|
+
raise_unless_signed_in(user)
|
94
|
+
contract = get_contract(contract)
|
95
|
+
!Signature.joins(:contract)
|
96
|
+
.where(:fine_print_contracts => {:name => contract.name},
|
97
|
+
:user_type => user.class.name,
|
98
|
+
:user_id => user.id).first.nil?
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.is_signed_in?(user)
|
102
|
+
user_signed_in_proc.call(user)
|
63
103
|
end
|
64
104
|
|
65
105
|
def self.is_admin?(user)
|
66
|
-
|
106
|
+
is_signed_in?(user) && user_admin_proc.call(user)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.raise_unless_signed_in(user)
|
110
|
+
raise IllegalState, 'User not signed in' unless is_signed_in?(user)
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.raise_unless_admin(user)
|
114
|
+
raise SecurityTransgression unless is_admin?(user)
|
67
115
|
end
|
68
116
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
-
|
1
|
+
FINE_PRINT_COPY_TASKS = ['assets/stylesheets',
|
2
|
+
'views/layouts',
|
3
|
+
'views',
|
4
|
+
'controllers']
|
2
5
|
|
3
6
|
namespace :fine_print do
|
4
7
|
namespace :install do
|
5
|
-
desc
|
8
|
+
desc 'Copy initializers from fine_print to application'
|
6
9
|
task :initializers do
|
7
10
|
Dir.glob(File.expand_path('../../../config/initializers/*.rb', __FILE__)) do |file|
|
8
11
|
if File.exists?(File.expand_path(File.basename(file), 'config/initializers'))
|
@@ -16,7 +19,7 @@ namespace :fine_print do
|
|
16
19
|
end
|
17
20
|
|
18
21
|
namespace :copy do
|
19
|
-
|
22
|
+
FINE_PRINT_COPY_TASKS.each do |path|
|
20
23
|
name = File.basename(path)
|
21
24
|
desc "Copy #{name} from fine_print to application"
|
22
25
|
task name.to_sym do
|
@@ -26,15 +29,15 @@ namespace :fine_print do
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
|
-
desc
|
32
|
+
desc 'Copy migrations from fine_print to application'
|
30
33
|
task :install do
|
31
|
-
Rake::Task[
|
32
|
-
Rake::Task[
|
34
|
+
Rake::Task['fine_print:install:initializers'].invoke
|
35
|
+
Rake::Task['fine_print:install:migrations'].invoke
|
33
36
|
end
|
34
37
|
|
35
|
-
desc
|
38
|
+
desc 'Copy assets, layouts, views and controllers from fine_print to application'
|
36
39
|
task :copy do
|
37
|
-
|
40
|
+
FINE_PRINT_COPY_TASKS.each do |path|
|
38
41
|
Rake::Task["fine_print:copy:#{File.basename(path)}"].invoke
|
39
42
|
end
|
40
43
|
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe ContractsController do
|
5
|
+
routes { FinePrint::Engine.routes }
|
6
|
+
|
7
|
+
before do
|
8
|
+
setup_controller_spec
|
9
|
+
@contract = FactoryGirl.create(:contract)
|
10
|
+
@contract.reload
|
11
|
+
end
|
12
|
+
|
13
|
+
it "won't get index unless authorized" do
|
14
|
+
get :index, :use_route => :fine_print
|
15
|
+
assert_redirected_to FinePrint.redirect_path
|
16
|
+
|
17
|
+
sign_in @user
|
18
|
+
get :index, :use_route => :fine_print
|
19
|
+
assert_redirected_to FinePrint.redirect_path
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'must get index if authorized' do
|
23
|
+
sign_in @admin
|
24
|
+
get :index, :use_route => :fine_print
|
25
|
+
assert_response :success
|
26
|
+
end
|
27
|
+
|
28
|
+
it "won't get new unless authorized" do
|
29
|
+
get :new, :use_route => :fine_print
|
30
|
+
assert_redirected_to FinePrint.redirect_path
|
31
|
+
|
32
|
+
sign_in @user
|
33
|
+
get :new, :use_route => :fine_print
|
34
|
+
assert_redirected_to FinePrint.redirect_path
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'must get new if authorized' do
|
38
|
+
sign_in @admin
|
39
|
+
get :new, :use_route => :fine_print
|
40
|
+
assert_response :success
|
41
|
+
end
|
42
|
+
|
43
|
+
it "won't create unless authorized" do
|
44
|
+
attributes = Hash.new
|
45
|
+
attributes[:name] = 'some_name'
|
46
|
+
attributes[:title] = 'Some title'
|
47
|
+
attributes[:content] = 'Some content'
|
48
|
+
|
49
|
+
post :create, :contract => attributes, :use_route => :fine_print
|
50
|
+
assert_redirected_to FinePrint.redirect_path
|
51
|
+
expect(assigns(:contract)).to be_nil
|
52
|
+
|
53
|
+
sign_in @user
|
54
|
+
post :create, :contract => attributes, :use_route => :fine_print
|
55
|
+
assert_redirected_to FinePrint.redirect_path
|
56
|
+
expect(assigns(:contract)).to be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'must create if authorized' do
|
60
|
+
sign_in @admin
|
61
|
+
attributes = Hash.new
|
62
|
+
attributes[:name] = 'some_name'
|
63
|
+
attributes[:title] = 'Some title'
|
64
|
+
attributes[:content] = 'Some content'
|
65
|
+
|
66
|
+
post :create, :contract => attributes, :use_route => :fine_print
|
67
|
+
assert_redirected_to assigns(:contract)
|
68
|
+
expect(assigns(:contract).errors).to be_empty
|
69
|
+
expect(assigns(:contract).name).to eq 'some_name'
|
70
|
+
expect(assigns(:contract).title).to eq 'Some title'
|
71
|
+
expect(assigns(:contract).content).to eq 'Some content'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "won't edit unless authorized" do
|
75
|
+
get :edit, :id => @contract.id, :use_route => :fine_print
|
76
|
+
assert_redirected_to FinePrint.redirect_path
|
77
|
+
|
78
|
+
sign_in @user
|
79
|
+
get :edit, :id => @contract.id, :use_route => :fine_print
|
80
|
+
assert_redirected_to FinePrint.redirect_path
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'must edit if authorized' do
|
84
|
+
sign_in @admin
|
85
|
+
get :edit, :id => @contract.id, :use_route => :fine_print
|
86
|
+
assert_response :success
|
87
|
+
end
|
88
|
+
|
89
|
+
it "won't update unless authorized" do
|
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
|
97
|
+
|
98
|
+
put :update, :id => @contract.id, :contract => attributes, :use_route => :fine_print
|
99
|
+
assert_redirected_to FinePrint.redirect_path
|
100
|
+
@contract.reload
|
101
|
+
expect(@contract.name).to eq name
|
102
|
+
expect(@contract.title).to eq title
|
103
|
+
expect(@contract.content).to eq content
|
104
|
+
|
105
|
+
sign_in @user
|
106
|
+
put :update, :id => @contract.id, :contract => attributes, :use_route => :fine_print
|
107
|
+
assert_redirected_to FinePrint.redirect_path
|
108
|
+
@contract.reload
|
109
|
+
expect(@contract.name).to eq name
|
110
|
+
expect(@contract.title).to eq title
|
111
|
+
expect(@contract.content).to eq content
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'must update if authorized' do
|
115
|
+
attributes = Hash.new
|
116
|
+
attributes[:name] = 'some_name'
|
117
|
+
attributes[:title] = 'Some title'
|
118
|
+
attributes[:content] = 'Some content'
|
119
|
+
|
120
|
+
sign_in @admin
|
121
|
+
put :update, :id => @contract.id, :contract => attributes, :use_route => :fine_print
|
122
|
+
assert_redirected_to @contract
|
123
|
+
@contract.reload
|
124
|
+
expect(@contract.errors).to be_empty
|
125
|
+
expect(@contract.name).to eq 'some_name'
|
126
|
+
expect(@contract.title).to eq 'Some title'
|
127
|
+
expect(@contract.content).to eq 'Some content'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "won't destroy unless authorized" do
|
131
|
+
delete :destroy, :id => @contract.id, :use_route => :fine_print
|
132
|
+
assert_redirected_to FinePrint.redirect_path
|
133
|
+
expect(Contract.find(@contract.id)).to eq @contract
|
134
|
+
|
135
|
+
sign_in @user
|
136
|
+
delete :destroy, :id => @contract.id, :use_route => :fine_print
|
137
|
+
assert_redirected_to FinePrint.redirect_path
|
138
|
+
expect(Contract.find(@contract.id)).to eq @contract
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'must destroy if authorized' do
|
142
|
+
sign_in @admin
|
143
|
+
delete :destroy, :id => @contract.id, :use_route => :fine_print
|
144
|
+
assert_redirected_to contracts_path
|
145
|
+
expect(Contract.find_by_id(@contract.id)).to be_nil
|
146
|
+
end
|
147
|
+
|
148
|
+
it "won't publish unless authorized" do
|
149
|
+
expect(@contract.is_published?).to eq false
|
150
|
+
put :publish, :id => @contract.id, :use_route => :fine_print
|
151
|
+
assert_redirected_to FinePrint.redirect_path
|
152
|
+
@contract.reload
|
153
|
+
expect(@contract.is_published?).to eq false
|
154
|
+
|
155
|
+
sign_in @user
|
156
|
+
put :publish, :id => @contract.id, :use_route => :fine_print
|
157
|
+
assert_redirected_to FinePrint.redirect_path
|
158
|
+
@contract.reload
|
159
|
+
expect(@contract.is_published?).to eq false
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'must publish if authorized' do
|
163
|
+
expect(@contract.is_published?).to eq false
|
164
|
+
sign_in @admin
|
165
|
+
|
166
|
+
put :publish, :id => @contract.id, :use_route => :fine_print
|
167
|
+
assert_redirected_to contracts_path
|
168
|
+
@contract.reload
|
169
|
+
expect(@contract.is_published?).to eq true
|
170
|
+
end
|
171
|
+
|
172
|
+
it "won't unpublish unless authorized" do
|
173
|
+
@contract.publish
|
174
|
+
expect(@contract.is_published?).to eq true
|
175
|
+
put :unpublish, :id => @contract.id, :use_route => :fine_print
|
176
|
+
assert_redirected_to FinePrint.redirect_path
|
177
|
+
@contract.reload
|
178
|
+
expect(@contract.is_published?).to eq true
|
179
|
+
|
180
|
+
sign_in @user
|
181
|
+
put :unpublish, :id => @contract.id, :use_route => :fine_print
|
182
|
+
assert_redirected_to FinePrint.redirect_path
|
183
|
+
@contract.reload
|
184
|
+
expect(@contract.is_published?).to eq true
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'must unpublish if authorized' do
|
188
|
+
@contract.publish
|
189
|
+
expect(@contract.is_published?).to eq true
|
190
|
+
|
191
|
+
sign_in @admin
|
192
|
+
put :unpublish, :id => @contract.id, :use_route => :fine_print
|
193
|
+
assert_redirected_to contracts_path
|
194
|
+
@contract.reload
|
195
|
+
expect(@contract.is_published?).to eq false
|
196
|
+
end
|
197
|
+
|
198
|
+
it "won't new_version unless authorized" do
|
199
|
+
@contract.publish
|
200
|
+
expect(@contract.is_published?).to eq true
|
201
|
+
|
202
|
+
put :new_version, :id => @contract.id, :use_route => :fine_print
|
203
|
+
assert_redirected_to FinePrint.redirect_path
|
204
|
+
expect(assigns(:contract)).to be_nil
|
205
|
+
|
206
|
+
sign_in @user
|
207
|
+
put :new_version, :id => @contract.id, :use_route => :fine_print
|
208
|
+
assert_redirected_to FinePrint.redirect_path
|
209
|
+
expect(assigns(:contract)).to be_nil
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'must new_version if authorized' do
|
213
|
+
@contract.publish
|
214
|
+
expect(@contract.is_published?).to eq true
|
215
|
+
|
216
|
+
sign_in @admin
|
217
|
+
put :new_version, :id => @contract.id, :use_route => :fine_print
|
218
|
+
assert_response :success
|
219
|
+
expect(assigns(:contract)).not_to be_nil
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe ContractsController do
|
5
|
+
routes { FinePrint::Engine.routes }
|
6
|
+
|
7
|
+
before do
|
8
|
+
setup_controller_spec
|
9
|
+
@contract = FactoryGirl.create(:contract)
|
10
|
+
@contract.reload
|
11
|
+
end
|
12
|
+
|
13
|
+
it "won't get index unless authorized" do
|
14
|
+
get :index, :use_route => :fine_print
|
15
|
+
assert_redirected_to FinePrint.redirect_path
|
16
|
+
|
17
|
+
sign_in @user
|
18
|
+
get :index, :use_route => :fine_print
|
19
|
+
assert_redirected_to FinePrint.redirect_path
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'must get index if authorized' do
|
23
|
+
sign_in @admin
|
24
|
+
get :index, :use_route => :fine_print
|
25
|
+
assert_response :success
|
26
|
+
end
|
27
|
+
|
28
|
+
it "won't get new unless authorized" do
|
29
|
+
get :new, :use_route => :fine_print
|
30
|
+
assert_redirected_to FinePrint.redirect_path
|
31
|
+
|
32
|
+
sign_in @user
|
33
|
+
get :new, :use_route => :fine_print
|
34
|
+
assert_redirected_to FinePrint.redirect_path
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'must get new if authorized' do
|
38
|
+
sign_in @admin
|
39
|
+
get :new, :use_route => :fine_print
|
40
|
+
assert_response :success
|
41
|
+
end
|
42
|
+
|
43
|
+
it "won't create unless authorized" do
|
44
|
+
attributes = Hash.new
|
45
|
+
attributes[:name] = 'some_name'
|
46
|
+
attributes[:title] = 'Some title'
|
47
|
+
attributes[:content] = 'Some content'
|
48
|
+
|
49
|
+
post :create, :contract => attributes, :use_route => :fine_print
|
50
|
+
assert_redirected_to FinePrint.redirect_path
|
51
|
+
expect(assigns(:contract)).to be_nil
|
52
|
+
|
53
|
+
sign_in @user
|
54
|
+
post :create, :contract => attributes, :use_route => :fine_print
|
55
|
+
assert_redirected_to FinePrint.redirect_path
|
56
|
+
expect(assigns(:contract)).to be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'must create if authorized' do
|
60
|
+
sign_in @admin
|
61
|
+
attributes = Hash.new
|
62
|
+
attributes[:name] = 'some_name'
|
63
|
+
attributes[:title] = 'Some title'
|
64
|
+
attributes[:content] = 'Some content'
|
65
|
+
|
66
|
+
post :create, :contract => attributes, :use_route => :fine_print
|
67
|
+
assert_redirected_to assigns(:contract)
|
68
|
+
expect(assigns(:contract).errors).to be_empty
|
69
|
+
expect(assigns(:contract).name).to eq 'some_name'
|
70
|
+
expect(assigns(:contract).title).to eq 'Some title'
|
71
|
+
expect(assigns(:contract).content).to eq 'Some content'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "won't edit unless authorized" do
|
75
|
+
get :edit, :id => @contract.id, :use_route => :fine_print
|
76
|
+
assert_redirected_to FinePrint.redirect_path
|
77
|
+
|
78
|
+
sign_in @user
|
79
|
+
get :edit, :id => @contract.id, :use_route => :fine_print
|
80
|
+
assert_redirected_to FinePrint.redirect_path
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'must edit if authorized' do
|
84
|
+
sign_in @admin
|
85
|
+
get :edit, :id => @contract.id, :use_route => :fine_print
|
86
|
+
assert_response :success
|
87
|
+
end
|
88
|
+
|
89
|
+
it "won't update unless authorized" do
|
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
|
97
|
+
|
98
|
+
put :update, :id => @contract.id, :contract => attributes, :use_route => :fine_print
|
99
|
+
assert_redirected_to FinePrint.redirect_path
|
100
|
+
expect(@contract.errors).not_to be_empty
|
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
|
+
|
106
|
+
sign_in @user
|
107
|
+
put :update, :id => @contract.id, :contract => attributes, :use_route => :fine_print
|
108
|
+
assert_redirected_to FinePrint.redirect_path
|
109
|
+
expect(@contract.errors).not_to be_empty
|
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
|
+
end
|
115
|
+
|
116
|
+
it 'must update if authorized' do
|
117
|
+
attributes = Hash.new
|
118
|
+
attributes[:name] = 'some_name'
|
119
|
+
attributes[:title] = 'Some title'
|
120
|
+
attributes[:content] = 'Some content'
|
121
|
+
|
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'
|
130
|
+
end
|
131
|
+
|
132
|
+
it "won't destroy unless authorized" do
|
133
|
+
delete :destroy, :id => @contract.id, :use_route => :fine_print
|
134
|
+
assert_redirected_to FinePrint.redirect_path
|
135
|
+
expect(Contract.find(@contract.id)).to eq @contract
|
136
|
+
|
137
|
+
sign_in @user
|
138
|
+
delete :destroy, :id => @contract.id, :use_route => :fine_print
|
139
|
+
assert_redirected_to FinePrint.redirect_path
|
140
|
+
expect(Contract.find(@contract.id)).to eq @contract
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'must destroy if authorized' do
|
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
|
148
|
+
end
|
149
|
+
|
150
|
+
it "won't publish unless authorized" do
|
151
|
+
expect(@contract.is_published?).to eq false
|
152
|
+
put :publish, :id => @contract.id, :use_route => :fine_print
|
153
|
+
assert_redirected_to FinePrint.redirect_path
|
154
|
+
@contract.reload
|
155
|
+
expect(@contract.is_published?).to eq false
|
156
|
+
|
157
|
+
sign_in @user
|
158
|
+
put :publish, :id => @contract.id, :use_route => :fine_print
|
159
|
+
assert_redirected_to FinePrint.redirect_path
|
160
|
+
@contract.reload
|
161
|
+
expect(@contract.is_published?).to eq false
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'must publish if authorized' do
|
165
|
+
expect(@contract.is_published?).to eq false
|
166
|
+
sign_in @admin
|
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
|
172
|
+
end
|
173
|
+
|
174
|
+
it "won't unpublish unless authorized" do
|
175
|
+
@contract.publish
|
176
|
+
expect(@contract.is_published?).to eq true
|
177
|
+
put :unpublish, :id => @contract.id, :use_route => :fine_print
|
178
|
+
assert_redirected_to FinePrint.redirect_path
|
179
|
+
@contract.reload
|
180
|
+
expect(@contract.is_published?).to eq true
|
181
|
+
|
182
|
+
sign_in @user
|
183
|
+
put :unpublish, :id => @contract.id, :use_route => :fine_print
|
184
|
+
assert_redirected_to FinePrint.redirect_path
|
185
|
+
@contract.reload
|
186
|
+
expect(@contract.is_published?).to eq true
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'must unpublish if authorized' do
|
190
|
+
@contract.publish
|
191
|
+
expect(@contract.is_published?).to eq true
|
192
|
+
|
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
|
198
|
+
end
|
199
|
+
|
200
|
+
it "won't new_version unless authorized" do
|
201
|
+
@contract.publish
|
202
|
+
expect(@contract.is_published?).to eq true
|
203
|
+
|
204
|
+
put :new_version, :id => @contract.id, :use_route => :fine_print
|
205
|
+
assert_redirected_to FinePrint.redirect_path
|
206
|
+
expect(assigns(:contract)).to be_nil
|
207
|
+
|
208
|
+
sign_in @user
|
209
|
+
put :new_version, :id => @contract.id, :use_route => :fine_print
|
210
|
+
assert_redirected_to FinePrint.redirect_path
|
211
|
+
expect(assigns(:contract)).to be_nil
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'must new_version if authorized' do
|
215
|
+
@contract.publish
|
216
|
+
expect(@contract.is_published?).to eq true
|
217
|
+
|
218
|
+
sign_in @admin
|
219
|
+
put :new_version, :id => @contract.id, :use_route => :fine_print
|
220
|
+
assert_response :success
|
221
|
+
expect(assigns(:contract)).not_to be_nil
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe HomeController do
|
5
|
+
before do
|
6
|
+
setup_controller_spec
|
7
|
+
end
|
8
|
+
|
9
|
+
it "won't get index unless authorized" do
|
10
|
+
get :index, :use_route => :fine_print
|
11
|
+
assert_response :redirect
|
12
|
+
|
13
|
+
sign_in @user
|
14
|
+
get :index, :use_route => :fine_print
|
15
|
+
assert_response :redirect
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'must get index if authorized' do
|
19
|
+
sign_in @user
|
20
|
+
@user.is_admin = true
|
21
|
+
get :index, :use_route => :fine_print
|
22
|
+
assert_response :success
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe HomeController do
|
5
|
+
before do
|
6
|
+
setup_controller_spec
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'wont get index unless authorized' do
|
10
|
+
get :index, :use_route => :fine_print
|
11
|
+
assert_response :redirect
|
12
|
+
|
13
|
+
sign_in @user
|
14
|
+
get :index, :use_route => :fine_print
|
15
|
+
assert_response :redirect
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'must get index if authorized' do
|
19
|
+
sign_in @user
|
20
|
+
@user.is_admin = true
|
21
|
+
get :index, :use_route => :fine_print
|
22
|
+
assert_response :success
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|