fine_print 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,25 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :contract, :class => FinePrint::Contract do
|
3
|
+
name { "Contract_#{SecureRandom.hex(4)}" }
|
4
|
+
title { Faker::Lorem.sentence(3) }
|
5
|
+
content { Faker::Lorem.paragraphs(2) }
|
6
|
+
|
7
|
+
factory :published_contract do
|
8
|
+
after(:create) {|instance| instance.publish }
|
9
|
+
end
|
10
|
+
|
11
|
+
factory :signed_contract do
|
12
|
+
after(:build) {|instance| instance.save; instance.publish }
|
13
|
+
|
14
|
+
ignore do
|
15
|
+
count 2
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:build) do |contract, evaluator|
|
19
|
+
evaluator.count.times do
|
20
|
+
contract.signatures << FactoryGirl.build(:signature)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :contract, :class => FinePrint::Contract do
|
3
|
+
|
4
|
+
name { "Contract_#{SecureRandom.hex(4)}" }
|
5
|
+
title { Faker::Lorem.sentence(3) }
|
6
|
+
content { Faker::Lorem.paragraphs(2) }
|
7
|
+
|
8
|
+
factory :published_contract do
|
9
|
+
after(:create) {|instance| instance.publish }
|
10
|
+
end
|
11
|
+
|
12
|
+
factory :signed_contract do
|
13
|
+
after(:build) {|instance| instance.save; instance.publish }
|
14
|
+
|
15
|
+
ignore do
|
16
|
+
count 2
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:build) do |contract, evaluator|
|
20
|
+
evaluator.count.times do
|
21
|
+
contract.signatures << FactoryGirl.build(:signature)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/fine_print_spec.rb~
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe FinePrint do
|
4
|
+
it 'gets unsigned contracts' do
|
5
|
+
alpha_1 = FactoryGirl.create(:published_contract, :name => 'alpha')
|
6
|
+
beta_1 = FactoryGirl.create(:published_contract, :name => 'beta')
|
7
|
+
|
8
|
+
user = mock_model 'DummyUser', :id => -1
|
9
|
+
alpha_1_sig = FactoryGirl.create(:signature, :contract => alpha_1, :user => user)
|
10
|
+
beta_1_sig = FactoryGirl.create(:signature, :contract => beta_1, :user => user)
|
11
|
+
|
12
|
+
alpha_2 = alpha_1.draft_copy
|
13
|
+
alpha_2.update_attributes(:content => 'foo')
|
14
|
+
alpha_2.publish
|
15
|
+
|
16
|
+
expect(FinePrint.get_unsigned_contract_names(:names => ['beta', 'alpha'], :user => user)).to eq ['alpha']
|
6
17
|
end
|
7
18
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe ControllerAdditions do
|
5
|
+
it 'must add fine_print_get_signatures to ActionController and subclasses' do
|
6
|
+
expect(ActionController::Base.respond_to? :fine_print_get_signatures).to eq true
|
7
|
+
expect(DummyModelsController.respond_to? :fine_print_get_signatures).to eq true
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'must add fine_print_skip_signatures to ActionController and subclasses' do
|
11
|
+
expect(ActionController::Base.respond_to? :fine_print_skip_signatures).to eq true
|
12
|
+
expect(DummyModelsController.respond_to? :fine_print_skip_signatures).to eq true
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must add fine_print_return to ActionController instances' do
|
16
|
+
expect(ActionController::Base.new.respond_to?(:fine_print_return, true)).to eq true
|
17
|
+
expect(DummyModelsController.new.respond_to?(:fine_print_return, true)).to eq true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe ControllerAdditions do
|
5
|
+
it 'must add fine_print_get_signatures to ActionController and subclasses' do
|
6
|
+
expect(ActionController::Base.respond_to? :fine_print_get_signatures).to eq true
|
7
|
+
expect(DummyModelsController.respond_to? :fine_print_get_signatures).to eq true
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'must add fine_print_skip_signatures to ActionController and subclasses' do
|
11
|
+
expect(ActionController::Base.respond_to? :fine_print_skip_signatures).to eq true
|
12
|
+
expect(DummyModelsController.respond_to? :fine_print_skip_signatures).to eq true
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must add fine_print_return to ActionController instances' do
|
16
|
+
expect(ActionController::Base.new.respond_to?(:fine_print_return, true)).to eq true
|
17
|
+
expect(DummyModelsController.new.respond_to?(:fine_print_return, true)).to eq true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FinePrint do
|
4
|
+
before :each do
|
5
|
+
@alpha_1 = FactoryGirl.create(:published_contract, :name => 'alpha')
|
6
|
+
@beta_1 = FactoryGirl.create(:published_contract, :name => 'beta')
|
7
|
+
|
8
|
+
@user = mock_model 'DummyUser', :id => -1
|
9
|
+
@alpha_1_sig = FactoryGirl.create(:signature, :contract => @alpha_1, :user => @user)
|
10
|
+
@beta_1_sig = FactoryGirl.create(:signature, :contract => @beta_1, :user => @user)
|
11
|
+
|
12
|
+
@alpha_2 = @alpha_1.draft_copy
|
13
|
+
@alpha_2.update_attribute(:content, 'foo')
|
14
|
+
@alpha_2.publish
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'gets contracts' do
|
18
|
+
expect(FinePrint.get_contract(@beta_1)).to eq @beta_1
|
19
|
+
expect(FinePrint.get_contract(@beta_1.id)).to eq @beta_1
|
20
|
+
expect(FinePrint.get_contract('beta')).to eq @beta_1
|
21
|
+
expect(FinePrint.get_contract(@alpha_1)).to eq @alpha_1
|
22
|
+
expect(FinePrint.get_contract(@alpha_1.id)).to eq @alpha_1
|
23
|
+
expect(FinePrint.get_contract('alpha')).to eq @alpha_2
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'gets unsigned contracts' do
|
27
|
+
expect(FinePrint.get_unsigned_contract_names(['beta', 'alpha'], @user)).to eq ['alpha']
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'allows users to sign contracts' do
|
31
|
+
expect(FinePrint.signed_contract?(@alpha_1, @user)).to eq true
|
32
|
+
expect(FinePrint.signed_contract?(@alpha_2, @user)).to eq false
|
33
|
+
expect(FinePrint.signed_contract?(@beta_1, @user)).to eq true
|
34
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_1, @user)).to eq true
|
35
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_2, @user)).to eq true
|
36
|
+
expect(FinePrint.signed_any_contract_version?(@beta_1, @user)).to eq true
|
37
|
+
|
38
|
+
expect(FinePrint.sign_contract(@alpha_2, @user)).to be_a FinePrint::Signature
|
39
|
+
|
40
|
+
expect(FinePrint.signed_contract?(@alpha_1, @user)).to eq true
|
41
|
+
expect(FinePrint.signed_contract?(@alpha_2, @user)).to eq true
|
42
|
+
expect(FinePrint.signed_contract?(@beta_1, @user)).to eq true
|
43
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_1, @user)).to eq true
|
44
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_2, @user)).to eq true
|
45
|
+
expect(FinePrint.signed_any_contract_version?(@beta_1, @user)).to eq true
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FinePrint do
|
4
|
+
before :each do
|
5
|
+
@alpha_1 = FactoryGirl.create(:published_contract, :name => 'alpha')
|
6
|
+
@beta_1 = FactoryGirl.create(:published_contract, :name => 'beta')
|
7
|
+
|
8
|
+
@user = mock_model 'DummyUser', :id => -1
|
9
|
+
@alpha_1_sig = FactoryGirl.create(:signature, :contract => @alpha_1, :user => @user)
|
10
|
+
@beta_1_sig = FactoryGirl.create(:signature, :contract => @beta_1, :user => @user)
|
11
|
+
|
12
|
+
@alpha_2 = @alpha_1.draft_copy
|
13
|
+
@alpha_2.update_attribute(:content, 'foo')
|
14
|
+
@alpha_2.publish
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'gets contracts' do
|
18
|
+
expect(FinePrint.get_contract(@beta_1)).to eq @beta_1
|
19
|
+
expect(FinePrint.get_contract(@beta_1.id)).to eq @beta_1
|
20
|
+
expect(FinePrint.get_contract('beta')).to eq @beta_1
|
21
|
+
expect(FinePrint.get_contract(@alpha_1)).to eq @alpha_1
|
22
|
+
expect(FinePrint.get_contract(@alpha_1.id)).to eq @alpha_1
|
23
|
+
expect(FinePrint.get_contract('alpha')).to eq @alpha_2
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'gets unsigned contracts' do
|
27
|
+
expect(FinePrint.get_unsigned_contract_names(['beta', 'alpha'], @user)).to eq ['alpha']
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'allows users to sign contracts' do
|
31
|
+
expect(FinePrint.signed_contract?(@alpha_1, @user)).to eq true
|
32
|
+
expect(FinePrint.signed_contract?(@alpha_2, @user)).to eq false
|
33
|
+
expect(FinePrint.signed_contract?(@beta_1, @user)).to eq true
|
34
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_1, @user)).to eq true
|
35
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_2, @user)).to eq true
|
36
|
+
expect(FinePrint.signed_any_contract_version?(@beta_1, @user)).to eq true
|
37
|
+
|
38
|
+
expect(FinePrint.sign_contract(@alpha_2, @user)).to be_a FinePrint::Signature
|
39
|
+
|
40
|
+
expect(FinePrint.signed_contract?(@alpha_1, @user)).to eq true
|
41
|
+
expect(FinePrint.signed_contract?(@alpha_2, @user)).to eq true
|
42
|
+
expect(FinePrint.signed_contract?(@beta_1, @user)).to eq true
|
43
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_1, @user)).to eq true
|
44
|
+
expect(FinePrint.signed_any_contract_version?(@alpha_2, @user)).to eq true
|
45
|
+
expect(FinePrint.signed_any_contract_version?(@beta_1, @user)).to eq true
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe Contract do
|
5
|
+
it 'can be published and unpublished' do
|
6
|
+
contract = FactoryGirl.create(:contract)
|
7
|
+
expect(contract.is_published?).to be_false
|
8
|
+
expect(contract.version).to be_nil
|
9
|
+
expect(contract.is_latest?).to be_false
|
10
|
+
expect(contract.can_be_updated?).to be_true
|
11
|
+
expect(contract.can_be_published?).to be_true
|
12
|
+
expect(contract.can_be_unpublished?).to be_false
|
13
|
+
|
14
|
+
contract.unpublish
|
15
|
+
expect(contract.errors).not_to be_empty
|
16
|
+
contract.errors.clear
|
17
|
+
expect(contract.errors).to be_empty
|
18
|
+
contract.publish
|
19
|
+
expect(contract.errors).to be_empty
|
20
|
+
expect(contract.is_published?).to be_true
|
21
|
+
expect(contract.version).to be 1
|
22
|
+
expect(contract.is_latest?).to be_true
|
23
|
+
expect(contract.can_be_updated?).to be_true
|
24
|
+
expect(contract.can_be_published?).to be_false
|
25
|
+
expect(contract.can_be_unpublished?).to be_true
|
26
|
+
|
27
|
+
contract.publish
|
28
|
+
expect(contract.errors).not_to be_empty
|
29
|
+
contract.errors.clear
|
30
|
+
expect(contract.errors).to be_empty
|
31
|
+
contract.unpublish
|
32
|
+
expect(contract.errors).to be_empty
|
33
|
+
expect(contract.is_published?).to be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can't be modified after a user signs" do
|
37
|
+
contract = FactoryGirl.create(:contract)
|
38
|
+
|
39
|
+
contract.publish
|
40
|
+
expect(contract.is_published?).to be_true
|
41
|
+
expect(contract.can_be_updated?).to be_true
|
42
|
+
expect(contract.can_be_published?).to be_false
|
43
|
+
expect(contract.can_be_unpublished?).to be_true
|
44
|
+
|
45
|
+
ua = FactoryGirl.create(:signature, :contract => contract)
|
46
|
+
contract.reload
|
47
|
+
expect(contract.can_be_updated?).to be_false
|
48
|
+
expect(contract.can_be_published?).to be_false
|
49
|
+
expect(contract.can_be_unpublished?).to be_false
|
50
|
+
|
51
|
+
contract.save
|
52
|
+
expect(contract.errors).not_to be_empty
|
53
|
+
contract.errors.clear
|
54
|
+
expect(contract.errors).to be_empty
|
55
|
+
contract.unpublish
|
56
|
+
expect(contract.errors).not_to be_empty
|
57
|
+
expect(contract.is_published?).to be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'results in a new version if a copy is published' do
|
61
|
+
contract = FactoryGirl.create(:published_contract)
|
62
|
+
expect(contract.version).to eq 1
|
63
|
+
new_version = contract.draft_copy
|
64
|
+
expect(new_version.save).to be_true
|
65
|
+
new_version.publish
|
66
|
+
expect(new_version.version).to eq 2
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'results in a first version if a name is changed after publishing' do
|
70
|
+
contract = FactoryGirl.create(:published_contract)
|
71
|
+
expect(contract.version).to eq 1
|
72
|
+
new_version = contract.draft_copy
|
73
|
+
new_version.name = 'Joe'
|
74
|
+
expect(new_version.save).to be_true
|
75
|
+
new_version.publish
|
76
|
+
expect(new_version.version).to eq 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe Contract do
|
5
|
+
it 'can be published and unpublished' do
|
6
|
+
contract = FactoryGirl.create(:contract)
|
7
|
+
expect(contract.is_published?).to be_false
|
8
|
+
expect(contract.version).to be_nil
|
9
|
+
expect(contract.is_latest?).to be_false
|
10
|
+
expect(contract.can_be_updated?).to be_true
|
11
|
+
expect(contract.can_be_published?).to be_true
|
12
|
+
expect(contract.can_be_unpublished?).to be_false
|
13
|
+
|
14
|
+
contract.unpublish
|
15
|
+
expect(contract.errors).not_to be_empty
|
16
|
+
contract.errors.clear
|
17
|
+
expect(contract.errors).to be_empty
|
18
|
+
contract.publish
|
19
|
+
expect(contract.errors).to be_empty
|
20
|
+
expect(contract.is_published?).to be_true
|
21
|
+
expect(contract.version).to be 1
|
22
|
+
expect(contract.is_latest?).to be_true
|
23
|
+
expect(contract.can_be_updated?).to be_true
|
24
|
+
expect(contract.can_be_published?).to be_false
|
25
|
+
expect(contract.can_be_unpublished?).to be_true
|
26
|
+
|
27
|
+
contract.publish
|
28
|
+
expect(contract.errors).not_to be_empty
|
29
|
+
contract.errors.clear
|
30
|
+
expect(contract.errors).to be_empty
|
31
|
+
contract.unpublish
|
32
|
+
expect(contract.errors).to be_empty
|
33
|
+
expect(contract.is_published?).to be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can't be modified after a user signs" do
|
37
|
+
contract = FactoryGirl.create(:contract)
|
38
|
+
|
39
|
+
contract.publish
|
40
|
+
expect(contract.is_published?).to be_true
|
41
|
+
contract.reload
|
42
|
+
expect(contract.can_be_updated?).to be_true
|
43
|
+
expect(contract.can_be_published?).to be_false
|
44
|
+
expect(contract.can_be_unpublished?).to be_true
|
45
|
+
|
46
|
+
ua = FactoryGirl.create(:signature, :contract => contract)
|
47
|
+
contract.reload
|
48
|
+
expect(contract.can_be_updated?).to be_false
|
49
|
+
expect(contract.can_be_published?).to be_false
|
50
|
+
expect(contract.can_be_unpublished?).to be_false
|
51
|
+
|
52
|
+
contract.save
|
53
|
+
expect(contract.errors).not_to be_empty
|
54
|
+
contract.errors.clear
|
55
|
+
expect(contract.errors).to be_empty
|
56
|
+
contract.unpublish
|
57
|
+
expect(contract.errors).not_to be_empty
|
58
|
+
expect(contract.is_published?).to be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'results in a new version if a copy is published' do
|
62
|
+
contract = FactoryGirl.create(:published_contract)
|
63
|
+
expect(contract.version).to eq 1
|
64
|
+
new_version = contract.draft_copy
|
65
|
+
expect(new_version.save).to be_true
|
66
|
+
new_version.publish
|
67
|
+
expect(new_version.version).to eq 2
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'results in a first version if a name is changed after publishing' do
|
71
|
+
contract = FactoryGirl.create(:published_contract)
|
72
|
+
expect(contract.version).to eq 1
|
73
|
+
new_version = contract.draft_copy
|
74
|
+
new_version.name = 'Joe'
|
75
|
+
expect(new_version.save).to be_true
|
76
|
+
new_version.publish
|
77
|
+
expect(new_version.version).to eq 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe Signature do
|
5
|
+
it 'can''t be associated with unpublished contracts' do
|
6
|
+
contract = FactoryGirl.create(:contract)
|
7
|
+
expect(contract.is_published?).to be_false
|
8
|
+
expect(contract.can_be_updated?).to be_true
|
9
|
+
|
10
|
+
sig = FactoryGirl.build(:signature)
|
11
|
+
sig.contract = contract
|
12
|
+
expect(sig.save).to be_false
|
13
|
+
|
14
|
+
contract.reload
|
15
|
+
expect(contract.can_be_updated?).to be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'prevents contract from being updated' do
|
19
|
+
sig = FactoryGirl.build(:signature)
|
20
|
+
contract = sig.contract
|
21
|
+
expect(contract.can_be_updated?).to be_true
|
22
|
+
|
23
|
+
sig.save!
|
24
|
+
contract.reload
|
25
|
+
expect(contract.can_be_updated?).to be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module FinePrint
|
4
|
+
describe Signature do
|
5
|
+
it 'can''t be associated with unpublished contracts' do
|
6
|
+
contract = FactoryGirl.create(:contract)
|
7
|
+
expect(contract.is_published?).to be_false
|
8
|
+
expect(contract.can_be_updated?).to be_true
|
9
|
+
|
10
|
+
sig = FactoryGirl.build(:signature)
|
11
|
+
sig.contract = contract
|
12
|
+
expect(sig.save).to be_false
|
13
|
+
|
14
|
+
contract.reload
|
15
|
+
expect(contract.can_be_updated?).to be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'prevents contract from being updated' do
|
19
|
+
sig = FactoryGirl.build(:signature)
|
20
|
+
contract = sig.contract
|
21
|
+
expect(contract.can_be_updated?).to be_true
|
22
|
+
|
23
|
+
sig.save!
|
24
|
+
contract.reload
|
25
|
+
expect(contract.can_be_updated?).to be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'factory_girl_rails'
|
7
|
+
require 'faker'
|
8
|
+
|
9
|
+
Rails.backtrace_cleaner.remove_silencers!
|
10
|
+
|
11
|
+
# Load support files
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.mock_with :rspec
|
16
|
+
config.use_transactional_fixtures = true
|
17
|
+
config.infer_base_class_for_anonymous_controllers = false
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
20
|
+
|
21
|
+
FinePrint::ApplicationController.class_eval do
|
22
|
+
include ApplicationHelper
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_controller_spec
|
26
|
+
class_eval { include ApplicationHelper }
|
27
|
+
sign_out
|
28
|
+
@user = FactoryGirl.create(:dummy_user)
|
29
|
+
@admin = FactoryGirl.create(:dummy_user)
|
30
|
+
@admin.is_admin = true
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'factory_girl_rails'
|
7
|
+
require 'faker'
|
8
|
+
|
9
|
+
Rails.backtrace_cleaner.remove_silencers!
|
10
|
+
|
11
|
+
# Load support files
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.mock_with :rspec
|
16
|
+
config.use_transactional_fixtures = true
|
17
|
+
config.infer_base_class_for_anonymous_controllers = false
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
20
|
+
|
21
|
+
FinePrint::ApplicationController.class_eval do
|
22
|
+
include ApplicationHelper
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_controller_spec
|
26
|
+
class_eval { include ApplicationHelper }
|
27
|
+
routes { FinePrint::Engine.routes }
|
28
|
+
sign_out
|
29
|
+
@user = FactoryGirl.create(:dummy_user)
|
30
|
+
@admin = FactoryGirl.create(:dummy_user)
|
31
|
+
@admin.is_admin = true
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
require 'minitest/rails'
|
5
|
+
require 'factory_girl_rails'
|
6
|
+
require 'faker'
|
7
|
+
|
8
|
+
# To add Capybara feature tests add `gem "minitest-rails-capybara"`
|
9
|
+
# to the test group in the Gemfile and uncomment the following:
|
10
|
+
# require "minitest/rails/capybara"
|
11
|
+
|
12
|
+
# Uncomment for awesome colorful output
|
13
|
+
# require "minitest/pride"
|
14
|
+
|
15
|
+
Rails.backtrace_cleaner.remove_silencers!
|