dorsale 3.14.4 → 3.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/features/access.feature +17 -0
  4. data/features/billing_machine_invoices.feature +261 -0
  5. data/features/billing_machine_multiple_vat.feature +53 -0
  6. data/features/billing_machine_payment_terms.feature +19 -0
  7. data/features/billing_machine_quotations.feature +193 -0
  8. data/features/customer_vault_activity_types.feature +19 -0
  9. data/features/customer_vault_corporations.feature +95 -0
  10. data/features/customer_vault_filters.feature +14 -0
  11. data/features/customer_vault_individuals.feature +35 -0
  12. data/features/customer_vault_invoices.feature +10 -0
  13. data/features/customer_vault_links.feature +54 -0
  14. data/features/customer_vault_origins.feature +19 -0
  15. data/features/customer_vault_people.feature +25 -0
  16. data/features/customer_vault_search.feature +22 -0
  17. data/features/customer_vault_tasks.feature +35 -0
  18. data/features/expense_gun_categories.feature +19 -0
  19. data/features/expense_gun_expenses.feature +60 -0
  20. data/features/flyboy_task_comments.feature +21 -0
  21. data/features/flyboy_tasks.feature +122 -0
  22. data/features/flyboy_tasks_summary.feature +22 -0
  23. data/features/step_definitions/access_steps.rb +15 -0
  24. data/features/step_definitions/alexandrie_steps.rb +25 -0
  25. data/features/step_definitions/billing_machine_invoices_steps.rb +377 -0
  26. data/features/step_definitions/billing_machine_multiple_vat.rb +19 -0
  27. data/features/step_definitions/billing_machine_payment_terms_steps.rb +42 -0
  28. data/features/step_definitions/billing_machine_quotations_steps.rb +248 -0
  29. data/features/step_definitions/common_steps.rb +91 -0
  30. data/features/step_definitions/customer_vault_activity_types_steps.rb +42 -0
  31. data/features/step_definitions/customer_vault_corporations_steps.rb +218 -0
  32. data/features/step_definitions/customer_vault_filters_steps.rb +37 -0
  33. data/features/step_definitions/customer_vault_individuals_steps.rb +67 -0
  34. data/features/step_definitions/customer_vault_invoices_steps.rb +7 -0
  35. data/features/step_definitions/customer_vault_links_steps.rb +73 -0
  36. data/features/step_definitions/customer_vault_origins_steps.rb +42 -0
  37. data/features/step_definitions/customer_vault_people_steps.rb +26 -0
  38. data/features/step_definitions/customer_vault_search_steps.rb +48 -0
  39. data/features/step_definitions/customer_vault_tasks_steps.rb +34 -0
  40. data/features/step_definitions/expense_gun_categories_steps.rb +50 -0
  41. data/features/step_definitions/expense_gun_expenses_steps.rb +135 -0
  42. data/features/step_definitions/flyboy_task_comments_steps.rb +10 -0
  43. data/features/step_definitions/flyboy_tasks_steps.rb +196 -0
  44. data/features/step_definitions/tasks_summary_steps.rb +30 -0
  45. data/features/step_definitions/users_management_step.rb +29 -0
  46. data/features/support/env.rb +8 -0
  47. data/features/users_management.feature +18 -0
  48. data/lib/dorsale/version.rb +1 -1
  49. data/spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb +145 -0
  50. data/spec/controllers/dorsale/billing_machine/invoices_controller_spec.rb +153 -0
  51. data/spec/controllers/dorsale/billing_machine/quotations_controller_spec.rb +24 -0
  52. data/spec/controllers/dorsale/comments_controller_spec.rb +50 -0
  53. data/spec/controllers/dorsale/customer_vault/events_controller_spec.rb +42 -0
  54. data/spec/controllers/dorsale/customer_vault/people_controller_spec.rb +129 -0
  55. data/spec/controllers/dorsale/expense_gun/expenses_controller_spec.rb +55 -0
  56. data/spec/controllers/dorsale/flyboy/task_comments_controller_spec.rb +40 -0
  57. data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +349 -0
  58. data/spec/factories/alexandrie_attachment_types.rb +5 -0
  59. data/spec/factories/alexandrie_attachments.rb +16 -0
  60. data/spec/factories/billing_machine_invoice_lines.rb +9 -0
  61. data/spec/factories/billing_machine_invoices.rb +9 -0
  62. data/spec/factories/billing_machine_payment_terms.rb +5 -0
  63. data/spec/factories/billing_machine_quotation_lines.rb +9 -0
  64. data/spec/factories/billing_machine_quotations.rb +9 -0
  65. data/spec/factories/customer_vault_activity_types.rb +5 -0
  66. data/spec/factories/customer_vault_corporations.rb +13 -0
  67. data/spec/factories/customer_vault_event.rb +13 -0
  68. data/spec/factories/customer_vault_individuals.rb +17 -0
  69. data/spec/factories/customer_vault_links.rb +7 -0
  70. data/spec/factories/customer_vault_origins.rb +5 -0
  71. data/spec/factories/dorsale_addresses.rb +9 -0
  72. data/spec/factories/dorsale_comments.rb +7 -0
  73. data/spec/factories/expense_gun_categories.rb +7 -0
  74. data/spec/factories/expense_gun_expense_lines.rb +11 -0
  75. data/spec/factories/expense_gun_expenses.rb +13 -0
  76. data/spec/factories/flyboy_task_comments.rb +9 -0
  77. data/spec/factories/flyboy_tasks.rb +8 -0
  78. data/spec/files/avatar.png +0 -0
  79. data/spec/files/pdf.pdf +0 -0
  80. data/spec/mailers/user_mailer_spec.rb +21 -0
  81. data/spec/models/dorsale/address_spec.rb +46 -0
  82. data/spec/models/dorsale/alexandrie/attachment_spec.rb +36 -0
  83. data/spec/models/dorsale/alexandrie/attachment_type_spec.rb +11 -0
  84. data/spec/models/dorsale/billing_machine/invoice_line_spec.rb +52 -0
  85. data/spec/models/dorsale/billing_machine/invoice_spec.rb +258 -0
  86. data/spec/models/dorsale/billing_machine/quotation_line_spec.rb +51 -0
  87. data/spec/models/dorsale/billing_machine/quotation_spec.rb +213 -0
  88. data/spec/models/dorsale/billing_machine_spec.rb +57 -0
  89. data/spec/models/dorsale/comment_spec.rb +24 -0
  90. data/spec/models/dorsale/customer_vault/activity_type_spec.rb +10 -0
  91. data/spec/models/dorsale/customer_vault/corporation_spec.rb +33 -0
  92. data/spec/models/dorsale/customer_vault/event_spec.rb +22 -0
  93. data/spec/models/dorsale/customer_vault/individual_spec.rb +44 -0
  94. data/spec/models/dorsale/customer_vault/link_spec.rb +14 -0
  95. data/spec/models/dorsale/customer_vault/origin_spec.rb +8 -0
  96. data/spec/models/dorsale/customer_vault/person_spec.rb +112 -0
  97. data/spec/models/dorsale/email_spec.rb +39 -0
  98. data/spec/models/dorsale/expense_gun/category_spec.rb +9 -0
  99. data/spec/models/dorsale/expense_gun/expense_line_spec.rb +53 -0
  100. data/spec/models/dorsale/expense_gun/expense_spec.rb +176 -0
  101. data/spec/models/dorsale/flyboy/task_comment_spec.rb +54 -0
  102. data/spec/models/dorsale/flyboy/task_spec.rb +254 -0
  103. data/spec/models/dorsale/i18n_spec.rb +30 -0
  104. data/spec/models/dorsale/users_spec.rb +65 -0
  105. data/spec/pdfs/dorsale/billing_machine/invoice_multiple_vat_pdf_spec.rb +42 -0
  106. data/spec/pdfs/dorsale/billing_machine/invoice_single_vat_pdf_spec.rb +42 -0
  107. data/spec/pdfs/dorsale/billing_machine/quotation_multiple_vat_pdf_spec.rb +42 -0
  108. data/spec/pdfs/dorsale/billing_machine/quotation_single_vat_pdf_spec.rb +55 -0
  109. data/spec/pdfs/dorsale/expense_gun/expense_pdf_spec.rb +11 -0
  110. data/spec/rails_helper.rb +57 -0
  111. data/spec/routing/dorsale/alexandrie/attachments_routing_spec.rb +32 -0
  112. data/spec/routing/dorsale/billing_machine/invoices_routing_spec.rb +67 -0
  113. data/spec/routing/dorsale/billing_machine/quotations_routing_spec.rb +67 -0
  114. data/spec/routing/dorsale/comments_routing_spec.rb +23 -0
  115. data/spec/routing/dorsale/customer_vault/activity_types_routing_spec.rb +40 -0
  116. data/spec/routing/dorsale/customer_vault/events_routing_spec.rb +12 -0
  117. data/spec/routing/dorsale/customer_vault/origins_routing_spec.rb +40 -0
  118. data/spec/routing/dorsale/customer_vault/people_routing_spec.rb +109 -0
  119. data/spec/routing/dorsale/expense_gun/expenses_routing_spec.rb +62 -0
  120. data/spec/routing/dorsale/flyboy/task_comments_routing_spec.rb +11 -0
  121. data/spec/routing/dorsale/flyboy/tasks_routing_spec.rb +51 -0
  122. data/spec/routing/dorsale/users_routing_spec.rb +38 -0
  123. data/spec/services/dorsale/billing_machine/quotation/copy_spec.rb +55 -0
  124. data/spec/services/dorsale/billing_machine/quotation/statistics.rb +23 -0
  125. data/spec/services/dorsale/billing_machine/quotation/to_invoice_spec.rb +46 -0
  126. data/spec/services/dorsale/expense_gun/expense/copy_spec.rb +83 -0
  127. data/spec/services/dorsale/flyboy/task/copy_spec.rb +24 -0
  128. data/spec/services/dorsale/flyboy/task/snoozer_spec.rb +117 -0
  129. data/spec/spec_helper.rb +86 -0
  130. data/spec/support/devise.rb +3 -0
  131. data/spec/support/message_delivery.rb +5 -0
  132. metadata +258 -2
@@ -0,0 +1,14 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::Link, type: :model do
4
+ it "should have a valid factory" do
5
+ link = build(:customer_vault_link)
6
+ expect(link).to be_valid
7
+ end
8
+
9
+ it { should belong_to :alice }
10
+ it { should belong_to :bob }
11
+
12
+ it { should validate_presence_of :alice }
13
+ it { should validate_presence_of :bob }
14
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.describe ::Dorsale::CustomerVault::Origin, type: :model do
2
+ it { is_expected.to validate_presence_of :name }
3
+
4
+ it "should have a valid factory" do
5
+ origin = create(:customer_vault_origin)
6
+ expect(origin).to be_valid
7
+ end
8
+ end
@@ -0,0 +1,112 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::Person, type: :model do
4
+ describe "#links" do
5
+ let!(:c) { create(:customer_vault_corporation) }
6
+ let!(:i) { create(:customer_vault_individual) }
7
+ let!(:link) { create(:customer_vault_link, alice: c, bob: i, title: "a") }
8
+
9
+ it "should return links" do
10
+ expect(c.links).to eq [link]
11
+ link = c.links.first
12
+ expect(link.person).to eq c
13
+ expect(link.other_person).to eq i
14
+
15
+ expect(i.links).to eq [link]
16
+ link = i.links.first
17
+ expect(link.person).to eq i
18
+ expect(link.other_person).to eq c
19
+ end
20
+
21
+ describe "#destroy" do
22
+ it "should destroy links" do
23
+ c.destroy!
24
+ expect { link.reload }.to raise_error(ActiveRecord::RecordNotFound)
25
+ end
26
+ end
27
+ end # describe '#links'
28
+
29
+ it "should return self_and_related_events" do
30
+ corporation = create(:customer_vault_corporation)
31
+ individual = create(:customer_vault_individual, corporation: corporation)
32
+ corporation_event = create(:customer_vault_event, person: corporation)
33
+ individual_event = create(:customer_vault_event, person: individual)
34
+
35
+ expect(corporation.self_and_related_events).to \
36
+ contain_exactly(corporation_event, individual_event)
37
+ expect(individual.self_and_related_events).to contain_exactly(individual_event)
38
+ end
39
+
40
+ describe "address" do
41
+ let(:person_without_address) {
42
+ corporation = Dorsale::CustomerVault::Corporation.create!(name: "agilidée")
43
+ corporation.address.destroy!
44
+ corporation
45
+ }
46
+
47
+ it "should auto create address on build" do
48
+ corporation = Dorsale::CustomerVault::Corporation.new
49
+ expect(corporation.address).to be_present
50
+ end
51
+
52
+ it "should NOT auto create address on find" do
53
+ corporation = Dorsale::CustomerVault::Corporation.find(person_without_address.id)
54
+ expect(corporation.address).to be_nil
55
+ end
56
+
57
+ it "should auto create address before validation" do
58
+ corporation = Dorsale::CustomerVault::Corporation.find(person_without_address.id)
59
+ expect(corporation.address).to be_nil
60
+
61
+ corporation.save!
62
+ expect(corporation.address).to be_present
63
+ end
64
+ end # describe "address"
65
+
66
+ describe "emails" do
67
+ it "should strip email" do
68
+ individual = create(:customer_vault_individual, email: " myemail@example.org ")
69
+ expect(individual.email).to eq "myemail@example.org"
70
+ end
71
+
72
+ it "should create an array of strings without blank characters" do
73
+ test_individual = create(:customer_vault_individual, email: "primary@example.org")
74
+ test_individual.secondary_emails_str = " first@example.org \n second@example.org "
75
+ expect(test_individual.secondary_emails).to eq ["first@example.org", "second@example.org"]
76
+ end
77
+
78
+ it "should return one object in the scope" do
79
+ individual = create(:customer_vault_individual,
80
+ :email => "primary@example.org",
81
+ :secondary_emails => ["first@example.org"],
82
+ )
83
+
84
+ individual2 = Dorsale::CustomerVault::Person.having_email("primary@example.org")
85
+ expect(individual2).to eq [individual]
86
+
87
+ individual3 = Dorsale::CustomerVault::Person.having_email("first@example.org")
88
+ expect(individual3).to eq [individual]
89
+ end
90
+
91
+ it "should check whether a new email address already is in the database" do
92
+ individual = create(:customer_vault_individual,
93
+ :email => "primary@example.org",
94
+ :secondary_emails => ["first@example.org", "second@example.org"],
95
+ )
96
+
97
+ individual2 = create(:customer_vault_individual)
98
+ individual2.email = "primary@example.org"
99
+ expect(individual2).to be_invalid
100
+ expect(individual2.errors).to have_key :email
101
+ expect(individual2.errors).to_not have_key :secondary_emails
102
+ expect(individual2.errors).to_not have_key :secondary_emails_str
103
+
104
+ individual3 = create(:customer_vault_individual)
105
+ individual3.secondary_emails << "first@example.org"
106
+ expect(individual3).to be_invalid
107
+ expect(individual3.errors).to have_key :secondary_emails
108
+ expect(individual3.errors).to have_key :secondary_emails_str
109
+ expect(individual3.errors).to_not have_key :email
110
+ end
111
+ end # describe "emails"
112
+ end
@@ -0,0 +1,39 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::Email do
4
+ describe "validations" do
5
+ it "should validate :to format" do
6
+ email = described_class.new
7
+
8
+ expect(email).to allow_value("user@example.org").for(:to)
9
+ expect(email).to allow_value("user1@example.org,user2@example.org").for(:to)
10
+ expect(email).to allow_value("user1@example.org;user2@example.org").for(:to)
11
+ expect(email).to allow_value("User <user@example.com>").for(:to)
12
+ expect(email).to allow_value("<user@example.com>").for(:to)
13
+ expect(email).to allow_value("User <user@example.com>;user2@example.org").for(:to)
14
+
15
+ expect(email).to_not allow_value("user").for(:to)
16
+ expect(email).to_not allow_value("user@example.com>").for(:to)
17
+ expect(email).to_not allow_value("<user@example.com").for(:to)
18
+ expect(email).to_not allow_value("valid@example.com;invalid").for(:to)
19
+ end
20
+
21
+ it "should validate :cc format" do
22
+ email = described_class.new
23
+
24
+ expect(email).to allow_value("").for(:cc)
25
+
26
+ expect(email).to allow_value("user@example.org").for(:cc)
27
+ expect(email).to allow_value("user1@example.org,user2@example.org").for(:cc)
28
+ expect(email).to allow_value("user1@example.org;user2@example.org").for(:cc)
29
+ expect(email).to allow_value("User <user@example.com>").for(:cc)
30
+ expect(email).to allow_value("<user@example.com>").for(:cc)
31
+ expect(email).to allow_value("User <user@example.com>;user2@example.org").for(:cc)
32
+
33
+ expect(email).to_not allow_value("user").for(:cc)
34
+ expect(email).to_not allow_value("user@example.com>").for(:cc)
35
+ expect(email).to_not allow_value("<user@example.com").for(:cc)
36
+ expect(email).to_not allow_value("valid@example.com;invalid").for(:to)
37
+ end
38
+ end # describe "validations" do
39
+ end
@@ -0,0 +1,9 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::ExpenseGun::Category, type: :model do
4
+ it { is_expected.to validate_presence_of :name }
5
+
6
+ it "category factory should be valid?" do
7
+ expect(build(:expense_gun_category)).to be_valid
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::ExpenseGun::ExpenseLine, type: :model do
4
+ it { is_expected.to belong_to :expense }
5
+ it { is_expected.to validate_presence_of :expense }
6
+ it { is_expected.to validate_presence_of :category }
7
+ it { is_expected.to validate_presence_of :name }
8
+ it { is_expected.to validate_presence_of :date }
9
+ it { is_expected.to validate_presence_of :total_all_taxes }
10
+ it { is_expected.to validate_presence_of :vat }
11
+ it { is_expected.to validate_presence_of :company_part }
12
+ it { is_expected.to validate_numericality_of(:total_all_taxes).is_greater_than_or_equal_to(0) }
13
+ it { is_expected.to validate_numericality_of(:company_part).is_greater_than_or_equal_to(0) }
14
+ it { is_expected.to validate_numericality_of(:company_part).is_less_than_or_equal_to(100) }
15
+
16
+ it "expense line factory should be valid?" do
17
+ expense_line = build :expense_gun_expense_line, expense: build(:expense_gun_expense)
18
+ expect(expense_line).to be_valid
19
+ end
20
+
21
+ it "#company_part should be 100 as default" do
22
+ expense_line = described_class.new
23
+ expect(expense_line.company_part).to eq 100.0
24
+ end
25
+
26
+ it "#employee_payback should be correct" do
27
+ expense_line = described_class.new(total_all_taxes: 100, company_part: 100)
28
+ expect(expense_line.employee_payback).to eq 100.0
29
+
30
+ expense_line = described_class.new(total_all_taxes: 250, company_part: 50)
31
+ expect(expense_line.employee_payback).to eq 125.0
32
+
33
+ expense_line = described_class.new(total_all_taxes: 200, company_part: 80)
34
+ expect(expense_line.employee_payback).to eq 160.0
35
+ end
36
+
37
+ it "#total_vat_deductible should be proportional to #company_part}" do
38
+ category = build(:expense_gun_category, vat_deductible: true)
39
+ expense_line = build(:expense_gun_expense_line,
40
+ :category => category,
41
+ :total_all_taxes => 200,
42
+ :vat => 40,
43
+ :company_part => 50,
44
+ )
45
+ expect(expense_line.total_vat_deductible).to eq 20.0
46
+ end
47
+
48
+ it "#total_vat_deductible should be 0 if categorie is non vat_decuctible" do
49
+ category = build(:expense_gun_category, vat_deductible: false)
50
+ expense_line = build(:expense_gun_expense_line, category: category)
51
+ expect(expense_line.total_vat_deductible).to eq 0.0
52
+ end
53
+ end
@@ -0,0 +1,176 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe Dorsale::ExpenseGun::Expense, type: :model do
4
+ it { is_expected.to have_many(:expense_lines).dependent(:destroy) }
5
+ it { is_expected.to validate_presence_of :name }
6
+ it { is_expected.to validate_presence_of :date }
7
+
8
+ it "expense factory should be valid?" do
9
+ expect(build(:expense_gun_expense)).to be_valid
10
+ end
11
+
12
+ it "default #date should be tody" do
13
+ expect(described_class.new.date).to eq Date.current
14
+ end
15
+
16
+ it "new expense should have new state" do
17
+ expect(described_class.new.current_state).to be :draft
18
+ end
19
+
20
+ describe "new state" do
21
+ before :each do
22
+ @expense = build(:expense_gun_expense)
23
+ end
24
+
25
+ it "new expense can be submitted" do
26
+ expect(@expense.go_to_submitted).to be true
27
+ expect(@expense.current_state).to be :submitted
28
+ end
29
+
30
+ it "new expense can't be accepted" do
31
+ expect(@expense.go_to_accepted).to be false
32
+ expect(@expense.current_state).to be :draft
33
+ end
34
+
35
+ it "new expense can't be refused" do
36
+ expect(@expense.go_to_refused).to be false
37
+ expect(@expense.current_state).to be :draft
38
+ end
39
+
40
+ it "new expense can be canceled" do
41
+ expect(@expense.go_to_canceled).to be true
42
+ expect(@expense.current_state).to be :canceled
43
+ end
44
+ end
45
+
46
+ describe "submitted state" do
47
+ before :each do
48
+ @expense = build(:expense_gun_expense)
49
+ @expense.go_to_submitted
50
+ end
51
+
52
+ it "submitted expense can be accepted" do
53
+ expect(@expense.go_to_accepted).to be true
54
+ expect(@expense.current_state).to be :accepted
55
+ end
56
+
57
+ it "submitted expense can be refused" do
58
+ expect(@expense.go_to_refused).to be true
59
+ expect(@expense.current_state).to be :refused
60
+ end
61
+
62
+ it "submitted expense can be canceled" do
63
+ expect(@expense.go_to_canceled).to be true
64
+ expect(@expense.current_state).to be :canceled
65
+ end
66
+ end
67
+
68
+ describe "acceped state" do
69
+ before :each do
70
+ @expense = build(:expense_gun_expense)
71
+ @expense.go_to_submitted
72
+ @expense.go_to_accepted
73
+ end
74
+
75
+ it "acceped expense can't be submitted" do
76
+ expect(@expense.go_to_submitted).to be false
77
+ expect(@expense.current_state).to be :accepted
78
+ end
79
+
80
+ it "acceped expense can't be refused" do
81
+ expect(@expense.go_to_refused).to be false
82
+ expect(@expense.current_state).to be :accepted
83
+ end
84
+
85
+ it "acceped expense can be canceled" do
86
+ expect(@expense.go_to_canceled).to be true
87
+ expect(@expense.current_state).to be :canceled
88
+ end
89
+ end
90
+
91
+ describe "refused state" do
92
+ before :each do
93
+ @expense = build(:expense_gun_expense)
94
+ @expense.go_to_submitted
95
+ @expense.go_to_refused
96
+ end
97
+
98
+ it "refused expense can't be submitted" do
99
+ expect(@expense.go_to_submitted).to be false
100
+ expect(@expense.current_state).to be :refused
101
+ end
102
+
103
+ it "refused expense can't be acceped" do
104
+ expect(@expense.go_to_accepted).to be false
105
+ expect(@expense.current_state).to be :refused
106
+ end
107
+
108
+ it "refused expense can't be canceled" do
109
+ expect(@expense.go_to_canceled).to be false
110
+ expect(@expense.current_state).to be :refused
111
+ end
112
+ end
113
+
114
+ describe "canceled state" do
115
+ before :each do
116
+ @expense = build(:expense_gun_expense)
117
+ @expense.go_to_canceled
118
+ end
119
+
120
+ it "canceled expense can't be submitted" do
121
+ expect(@expense.go_to_submitted).to be false
122
+ expect(@expense.current_state).to be :canceled
123
+ end
124
+
125
+ it "canceled expense can't be acceped" do
126
+ expect(@expense.go_to_accepted).to be false
127
+ expect(@expense.current_state).to be :canceled
128
+ end
129
+
130
+ it "canceled expense can't be refused" do
131
+ expect(@expense.go_to_refused).to be false
132
+ expect(@expense.current_state).to be :canceled
133
+ end
134
+ end
135
+
136
+ it "#total_all_taxes should return sum of lines" do
137
+ expense = build(:expense_gun_expense, expense_lines: [])
138
+ expense.expense_lines << build(:expense_gun_expense_line, total_all_taxes: 10)
139
+ expense.expense_lines << build(:expense_gun_expense_line, total_all_taxes: 10)
140
+ expect(expense.total_all_taxes).to eq 20.0
141
+ end
142
+
143
+ it "#total_employee_payback should return sum of lines" do
144
+ expense = build(:expense_gun_expense, expense_lines: [])
145
+
146
+ line1 = build(:expense_gun_expense_line, total_all_taxes: 10, company_part: 100)
147
+ expense.expense_lines << line1
148
+
149
+ line2 = build(:expense_gun_expense_line, total_all_taxes: 10, company_part: 50)
150
+ expense.expense_lines << line2
151
+
152
+ expect(expense.total_employee_payback).to eq 15.0
153
+ end
154
+
155
+ it "#total_vat_deductible should return sum of lines" do
156
+ expense = build(:expense_gun_expense, expense_lines: [])
157
+
158
+ category1 = build(:expense_gun_category, vat_deductible: true)
159
+ line1 = build(:expense_gun_expense_line, vat: 10, category: category1, company_part: 50)
160
+ expense.expense_lines << line1
161
+
162
+ category2 = build(:expense_gun_category, vat_deductible: false)
163
+ line2 = build(:expense_gun_expense_line, vat: 10, category: category2, company_part: 50)
164
+ expense.expense_lines << line2
165
+
166
+ expect(expense.total_vat_deductible).to eq 5.0
167
+ end
168
+
169
+ it "#may_edit? should return false unless expense is not submitted" do
170
+ expect(described_class.new(state: :draft).may_edit?).to be true
171
+ expect(described_class.new(state: :submitted).may_edit?).to be false
172
+ expect(described_class.new(state: :acceped).may_edit?).to be false
173
+ expect(described_class.new(state: :refused).may_edit?).to be false
174
+ expect(described_class.new(state: :canceled).may_edit?).to be false
175
+ end
176
+ end
@@ -0,0 +1,54 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::Flyboy::TaskComment do
4
+ it { is_expected.to belong_to(:task) }
5
+
6
+ it { is_expected.to validate_presence_of :task }
7
+ it { is_expected.to validate_presence_of :date }
8
+ it { is_expected.to validate_presence_of :description }
9
+
10
+ it { is_expected.to belong_to :author }
11
+ it { is_expected.to validate_presence_of :author }
12
+
13
+ it "should have a valid factory" do
14
+ expect(build(:flyboy_task_comment)).to be_valid
15
+ end
16
+
17
+ it "should update the task progress upon creation" do
18
+ task = create(:flyboy_task, progress: 10)
19
+ comment = create(:flyboy_task_comment, progress: 20, task: task)
20
+ expect(task.reload.progress).to eq(20)
21
+ end
22
+
23
+ it "should mark task as complete when progress == 100" do
24
+ task = create(:flyboy_task, progress: 10, done: false)
25
+ comment = create(:flyboy_task_comment, progress: 100, task: task)
26
+ expect(task.reload.done).to be true
27
+ end
28
+
29
+ it "should mark task as un complete when progress < 100" do
30
+ task = create(:flyboy_task, progress: 100, done: true)
31
+ comment = create(:flyboy_task_comment, progress: 90, task: task)
32
+ expect(task.reload.done).to be false
33
+ end
34
+
35
+ describe "default values" do
36
+ it "#new progress should be 0 if no task" do
37
+ expect(Dorsale::Flyboy::TaskComment.new.progress).to eq 0
38
+ end
39
+
40
+ it "#new progress should be task progress if task specified" do
41
+ task = create(:flyboy_task, progress: 50)
42
+ expect(task.comments.new.progress).to eq 50
43
+ end
44
+
45
+ it "#new progress should not override exisring progress" do
46
+ task = create(:flyboy_task)
47
+ comment1 = create(:flyboy_task_comment, task: task, progress: 30)
48
+ comment2 = create(:flyboy_task_comment, task: task, progress: 50)
49
+ expect(task.reload.progress).to eq 50
50
+ expect(comment1.reload.progress).to eq 30
51
+ expect(comment2.reload.progress).to eq 50
52
+ end
53
+ end
54
+ end