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,51 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::BillingMachine::QuotationLine do
4
+ it { is_expected.to belong_to :quotation }
5
+ it { is_expected.to validate_presence_of :quotation }
6
+
7
+ it { is_expected.to respond_to :quantity }
8
+ it { is_expected.to respond_to :label }
9
+ it { is_expected.to respond_to :vat_rate }
10
+ it { is_expected.to respond_to :total }
11
+ it { is_expected.to respond_to :unit }
12
+ it { is_expected.to respond_to :unit_price }
13
+
14
+ it "should have a valid factory" do
15
+ expect(build(:billing_machine_quotation_line)).to be_valid
16
+ end
17
+
18
+ describe "default values" do
19
+ it "quantity should be 0" do
20
+ expect(described_class.new.quantity).to eq 0
21
+ end
22
+
23
+ it "unit_price should be 0" do
24
+ expect(described_class.new.unit_price).to eq 0
25
+ end
26
+
27
+ it "vat_rate should be 0" do
28
+ expect(described_class.new.vat_rate).to eq ::Dorsale::BillingMachine.default_vat_rate
29
+ end
30
+ end
31
+
32
+ it "should be sorted by created_at" do
33
+ line1 = create(:billing_machine_quotation_line, :created_at => Time.zone.now + 1.minute)
34
+ line2 = create(:billing_machine_quotation_line, :created_at => Time.zone.now + 2.minutes)
35
+ line3 = create(:billing_machine_quotation_line, :created_at => Time.zone.now + 3.minutes)
36
+ line4 = create(:billing_machine_quotation_line, :created_at => Time.zone.now + 4.minutes)
37
+ line3.update!(:created_at => Time.zone.now + 5.minutes)
38
+ lines = described_class.all
39
+ expect(lines).to eq [line1, line2, line4, line3]
40
+ end
41
+
42
+ it "should update the total upon save" do
43
+ line = create(:billing_machine_quotation_line, quantity: 12.34, unit_price: 12.34, total: 0)
44
+ expect(line.total.to_f).to eq 152.28
45
+ end
46
+
47
+ it "should update the total gracefully with invalid data" do
48
+ line = create(:billing_machine_quotation_line, quantity: nil, unit_price: nil, total: 0)
49
+ expect(line.total.to_f).to eq 0
50
+ end
51
+ end
@@ -0,0 +1,213 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::BillingMachine::Quotation do
4
+ it { is_expected.to belong_to :customer }
5
+ it { is_expected.to belong_to :payment_term }
6
+ it { is_expected.to have_many(:lines).dependent(:destroy) }
7
+
8
+ it { is_expected.to validate_presence_of :date }
9
+ it { is_expected.to validate_presence_of :state }
10
+ it { is_expected.to validate_inclusion_of(:state).in_array(described_class::STATES) }
11
+ it { is_expected.to respond_to :date }
12
+ it { is_expected.to respond_to :label }
13
+ it { is_expected.to respond_to :vat_amount }
14
+ it { is_expected.to respond_to :comments }
15
+ it { is_expected.to respond_to :unique_index }
16
+ it { is_expected.to respond_to :commercial_discount }
17
+ it { is_expected.to respond_to :total_excluding_taxes }
18
+ it { is_expected.to respond_to :total_including_taxes }
19
+
20
+ it "should have a valid factory" do
21
+ expect(create(:billing_machine_quotation)).to be_valid
22
+ end
23
+
24
+ it "should return document_type" do
25
+ expect(described_class.new.document_type).to eq :quotation
26
+ end
27
+
28
+ describe "default values" do
29
+ it "default date should be today" do
30
+ expect(described_class.new.date).to eq Date.current
31
+ end
32
+
33
+ it "default expires_at should be date + 1 month" do
34
+ quotation = described_class.new(date: "21/12/2012")
35
+ expect(quotation.expires_at).to eq Date.parse("21/01/2013")
36
+ end
37
+
38
+ it "default state should be pending" do
39
+ expect(described_class.new.state).to eq "pending"
40
+ end
41
+ end
42
+
43
+ it "should work fine upon creation" do
44
+ quotation = build(:billing_machine_quotation)
45
+ quotation.lines << ::Dorsale::BillingMachine::QuotationLine.new(quantity: 1, unit_price: 10)
46
+ quotation.lines << ::Dorsale::BillingMachine::QuotationLine.new(quantity: 1, unit_price: 10)
47
+ quotation.save!
48
+ end
49
+
50
+ describe "unique_index" do
51
+ context "when unique index is 69" do
52
+ it "should be assigned upon creation" do
53
+ quotation1 = create(:billing_machine_quotation, date: "2014-02-01", unique_index: 69)
54
+ quotation2 = create(:billing_machine_quotation, date: "2014-02-01")
55
+ expect(quotation2.unique_index).to eq(70)
56
+ end
57
+ end
58
+
59
+ context "when unique index is nil" do
60
+ it "should be assigned upon creation" do
61
+ described_class.destroy_all
62
+ quotation1 = create(:billing_machine_quotation, date: "2014-02-01")
63
+ expect(quotation1.unique_index).to eq(1)
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "tracking_id" do
69
+ it "should return correct tracking_id" do
70
+ quotation = create(:billing_machine_quotation, date: "2014-02-01")
71
+ expect(quotation.tracking_id).to eq("2014-01")
72
+ end
73
+ end
74
+
75
+ describe "vat rate" do
76
+ it "default vat rate should be 20" do
77
+ expect(described_class.new.vat_rate).to eq ::Dorsale::BillingMachine.default_vat_rate
78
+ end
79
+
80
+ it "it should be specified vat rate" do
81
+ expect(build(:billing_machine_quotation, vat_rate: 12).vat_rate).to eq 12
82
+ end
83
+
84
+ it "it should be first line vat rate" do
85
+ quotation = create(:billing_machine_quotation)
86
+ line1 = create(:billing_machine_quotation_line, quotation: quotation, vat_rate: 10)
87
+ line2 = create(:billing_machine_quotation_line, quotation: quotation, vat_rate: 10)
88
+ expect(quotation.vat_rate).to eq 10
89
+ end
90
+
91
+ it "it should raise if multiple vat_rates" do
92
+ quotation = create(:billing_machine_quotation)
93
+ line1 = create(:billing_machine_quotation_line, quotation: quotation, vat_rate: 10)
94
+
95
+ expect {
96
+ line2 = create(:billing_machine_quotation_line, quotation: quotation, vat_rate: 15)
97
+ }.to raise_error(RuntimeError)
98
+ end
99
+
100
+ it "it should raise when vat mode is multiple" do
101
+ ::Dorsale::BillingMachine.vat_mode = :multiple
102
+ quotation = build(:billing_machine_quotation)
103
+ expect { quotation.vat_rate }.to raise_error(RuntimeError)
104
+ end
105
+ end
106
+
107
+ describe "totals" do
108
+ it "should be calculated upon saving" do
109
+ quotation = create(:billing_machine_quotation, commercial_discount: 10)
110
+
111
+ create(:billing_machine_quotation_line,
112
+ :vat_rate => 20,
113
+ :quantity => 10,
114
+ :unit_price => 5,
115
+ :quotation => quotation,
116
+ )
117
+
118
+ create(:billing_machine_quotation_line,
119
+ :vat_rate => 20,
120
+ :quantity => 10,
121
+ :unit_price => 5,
122
+ :quotation => quotation,
123
+ )
124
+
125
+ expect(quotation.total_excluding_taxes).to eq(90.0)
126
+ expect(quotation.vat_amount).to eq(18)
127
+ expect(quotation.total_including_taxes).to eq(108)
128
+ expect(quotation.balance).to eq(108)
129
+ end
130
+
131
+ it "should be calculated upon saving with different vat rates" do
132
+ Dorsale::BillingMachine.vat_mode = :multiple
133
+ quotation = create(:billing_machine_quotation, commercial_discount: 20)
134
+ create(:billing_machine_quotation_line,
135
+ :quantity => 10,
136
+ :vat_rate => 10,
137
+ :unit_price => 5,
138
+ :quotation => quotation,
139
+ )
140
+
141
+ create(:billing_machine_quotation_line,
142
+ :quantity => 10,
143
+ :vat_rate => 20,
144
+ :unit_price => 5,
145
+ :quotation => quotation,
146
+ )
147
+
148
+ expect(quotation.total_excluding_taxes).to eq(80)
149
+ expect(quotation.vat_amount).to eq(12)
150
+ expect(quotation.total_including_taxes).to eq(92)
151
+ expect(quotation.balance).to eq(92)
152
+ Dorsale::BillingMachine.vat_mode = :single
153
+ end
154
+
155
+ describe "VAT round" do
156
+ let(:quotation) {
157
+ quotation = create(:billing_machine_quotation,
158
+ :commercial_discount => 0,
159
+ )
160
+
161
+ create(:billing_machine_quotation_line,
162
+ :quantity => 12.34,
163
+ :unit_price => 12.34,
164
+ :vat_rate => 20,
165
+ :quotation => quotation,
166
+ ) # vat 30.45512 / total 152.2756
167
+
168
+ create(:billing_machine_quotation_line,
169
+ :quantity => 12.34,
170
+ :unit_price => 12.34,
171
+ :vat_rate => 20,
172
+ :quotation => quotation,
173
+ ) # vat 30.45512 / total 152.2756
174
+
175
+ quotation
176
+ }
177
+
178
+ after { Dorsale::BillingMachine.vat_round_by_line = nil }
179
+
180
+ it "should round VAT by line" do
181
+ Dorsale::BillingMachine.vat_round_by_line = true
182
+ expect(quotation.total_excluding_taxes.to_f).to eq(304.56)
183
+ expect(quotation.vat_amount.to_f).to eq(60.92)
184
+ expect(quotation.total_including_taxes.to_f).to eq(365.48)
185
+ expect(quotation.balance.to_f).to eq(365.48)
186
+ end
187
+
188
+ it "should round VAT globally" do
189
+ Dorsale::BillingMachine.vat_round_by_line = false
190
+ expect(quotation.total_excluding_taxes.to_f).to eq(304.56)
191
+ expect(quotation.vat_amount.to_f).to eq(60.91)
192
+ expect(quotation.total_including_taxes.to_f).to eq(365.47)
193
+ expect(quotation.balance.to_f).to eq(365.47)
194
+ end
195
+ end # describe "VAT round" do
196
+
197
+ it "should work fine even with empty lines" do
198
+ quotation = create(:billing_machine_quotation, commercial_discount: nil)
199
+
200
+ create(:billing_machine_quotation_line,
201
+ :quantity => nil,
202
+ :unit_price => nil,
203
+ :vat_rate => nil,
204
+ :quotation => quotation,
205
+ )
206
+
207
+ expect(quotation.total_excluding_taxes).to eq(0.0)
208
+ expect(quotation.vat_amount).to eq(0.0)
209
+ expect(quotation.total_including_taxes).to eq(0.0)
210
+ expect(quotation.balance).to eq(0.0)
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,57 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe Dorsale::BillingMachine do
4
+ let(:bm) {
5
+ ::Dorsale::BillingMachine
6
+ }
7
+
8
+ describe "::vat_mode" do
9
+ it "default vat_mode should be :single" do
10
+ expect(bm.vat_mode).to eq :single
11
+ expect(bm.invoice_pdf_model).to eq Dorsale::BillingMachine::InvoiceSingleVatPdf
12
+ expect(bm.quotation_pdf_model).to eq Dorsale::BillingMachine::QuotationSingleVatPdf
13
+ end
14
+
15
+ it "vat_mode should accept :multiple value" do
16
+ bm.vat_mode = :multiple
17
+ expect(bm.vat_mode).to eq :multiple
18
+ expect(bm.invoice_pdf_model).to eq Dorsale::BillingMachine::InvoiceMultipleVatPdf
19
+ expect(bm.quotation_pdf_model).to eq Dorsale::BillingMachine::QuotationMultipleVatPdf
20
+ end
21
+
22
+ it "vat_mode should not accept :abc value" do
23
+ expect {
24
+ bm.vat_mode = :abc
25
+ }.to raise_error(RuntimeError)
26
+ end
27
+ end # describe "::vat_mode"
28
+
29
+ describe "::vat_round_by_line" do
30
+ after { Dorsale::BillingMachine.vat_round_by_line = nil }
31
+
32
+ it "should return default value" do
33
+ expect(Dorsale::BillingMachine.vat_round_by_line).to eq false
34
+ end
35
+
36
+ it "should assign false value" do
37
+ Dorsale::BillingMachine.vat_round_by_line = false
38
+ expect(Dorsale::BillingMachine.vat_round_by_line).to eq false
39
+ end
40
+
41
+ it "should assign true value" do
42
+ Dorsale::BillingMachine.vat_round_by_line = true
43
+ expect(Dorsale::BillingMachine.vat_round_by_line).to eq true
44
+ end
45
+ end # describe "::vat_round_by_line"
46
+
47
+ describe "::default_currency" do
48
+ it "default currency should be €" do
49
+ expect(bm.default_currency).to eq "€"
50
+ end
51
+
52
+ it "assign an other default currency" do
53
+ bm.default_currency = "$"
54
+ expect(bm.default_currency).to eq "$"
55
+ end
56
+ end # describe "::default_currency"
57
+ end
@@ -0,0 +1,24 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe Dorsale::Comment, type: :model do
4
+ it { is_expected.to belong_to :author }
5
+ it { is_expected.to validate_presence_of :author }
6
+
7
+ it { is_expected.to belong_to :commentable }
8
+ it { is_expected.to validate_presence_of :commentable }
9
+
10
+ it { is_expected.to validate_presence_of :date }
11
+ it { is_expected.to_not validate_presence_of :title }
12
+
13
+ describe "factories" do
14
+ it "should have a valid factory" do
15
+ expect(create(:dorsale_comment)).to be_valid
16
+ end
17
+ end # describe "factories"
18
+
19
+ describe "default values" do
20
+ it "should set date" do
21
+ expect(described_class.new.date).to be_present
22
+ end
23
+ end # describe "default values"
24
+ end
@@ -0,0 +1,10 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::ActivityType, type: :model do
4
+ it { is_expected.to validate_presence_of :name }
5
+
6
+ it "should have a valid factory" do
7
+ activity_type = create(:customer_vault_activity_type)
8
+ expect(activity_type).to be_valid
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::Corporation, type: :model do
4
+ it { is_expected.to have_one(:address).dependent(:destroy) }
5
+ it { is_expected.to have_many :comments }
6
+ it { is_expected.to have_many :taggings }
7
+ it { is_expected.to have_many :tags }
8
+ it { is_expected.to have_many :individuals }
9
+ it { is_expected.to have_many(:tasks).dependent(:destroy) }
10
+ it { is_expected.to have_many(:events).dependent(:destroy) }
11
+
12
+ it { is_expected.to respond_to :legal_form }
13
+ it { is_expected.to respond_to :capital }
14
+ it { is_expected.to respond_to :immatriculation_number }
15
+ it { is_expected.to respond_to :naf }
16
+ it { is_expected.to respond_to :revenue }
17
+ it { is_expected.to respond_to :context }
18
+ it { is_expected.to respond_to :number_of_employees }
19
+ it { is_expected.to respond_to :societe_com }
20
+
21
+ it { is_expected.to belong_to :activity_type }
22
+ it { is_expected.to belong_to :origin }
23
+
24
+ it { is_expected.to have_many(:comments).dependent(:destroy) }
25
+
26
+ it { is_expected.to validate_presence_of :corporation_name }
27
+
28
+ it "should have a valid factory" do
29
+ corporation = create(:customer_vault_corporation)
30
+ expect(corporation).to be_valid
31
+ expect(Dorsale::Address.count).to eq 1
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::Event, type: :model do
4
+ it { is_expected.to belong_to :author }
5
+ it { is_expected.to belong_to :person }
6
+
7
+ it { is_expected.to validate_presence_of :person }
8
+ it { is_expected.to validate_presence_of :action }
9
+ it { is_expected.to validate_presence_of :contact_type }
10
+
11
+ it { is_expected.to_not validate_presence_of :author }
12
+
13
+ it "should have a valid factory" do
14
+ event = create(:customer_vault_event)
15
+ expect(event).to be_valid
16
+ end
17
+
18
+ it "should assign default values" do
19
+ expect(described_class.new.date).to be_present
20
+ expect(described_class.new.contact_type).to eq "contact"
21
+ end
22
+ end
@@ -0,0 +1,44 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::Individual, :type => :model do
4
+ it "should have a valid factory" do
5
+ individual = create(:customer_vault_individual)
6
+ expect(individual).to be_valid
7
+ expect(Dorsale::Address.count).to eq 1
8
+ end
9
+
10
+ it { is_expected.to have_one(:address).dependent(:destroy) }
11
+ it { is_expected.to belong_to :corporation }
12
+ it { is_expected.to have_many :comments }
13
+ it { is_expected.to have_many :taggings }
14
+ it { is_expected.to have_many :tags }
15
+ it { is_expected.to have_many(:tasks).dependent(:destroy) }
16
+ it { is_expected.to have_many(:comments).dependent(:destroy) }
17
+ it { is_expected.to have_many(:events).dependent(:destroy) }
18
+ it { is_expected.to validate_presence_of :first_name }
19
+ it { is_expected.to validate_presence_of :last_name }
20
+
21
+ it { is_expected.to respond_to :activity_type }
22
+ it { is_expected.to belong_to :origin }
23
+
24
+ it { is_expected.to respond_to :context }
25
+
26
+ describe "activity type" do
27
+ it "should have the same activity than his corporation" do
28
+ corporation = create(:customer_vault_corporation)
29
+ individual = create(:customer_vault_individual, corporation: corporation)
30
+ expect(individual.activity_type).to eq corporation.activity_type
31
+ end
32
+
33
+ it "should have no activity if no corporation" do
34
+ individual = create(:customer_vault_individual, corporation: nil)
35
+ expect(individual.activity_type).to eq nil
36
+ end
37
+
38
+ it "should have no activity if his corporation has no activity" do
39
+ corporation = create(:customer_vault_corporation, activity_type: nil)
40
+ individual = create(:customer_vault_individual, corporation: corporation)
41
+ expect(individual.activity_type).to eq nil
42
+ end
43
+ end
44
+ end