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,153 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::BillingMachine::InvoicesController, type: :controller do
4
+ routes { Dorsale::Engine.routes }
5
+
6
+ let(:user) { create(:user) }
7
+ before(:each) { sign_in(user) }
8
+
9
+ describe "#preview" do
10
+ render_views
11
+
12
+ it "should render show" do
13
+ post :preview
14
+ expect(response).to render_template(:show)
15
+ end
16
+
17
+ it "should not save" do
18
+ post :preview
19
+ @invoice = assigns(:invoice)
20
+ expect(@invoice).to be_valid
21
+ expect(@invoice).to_not be_persisted
22
+ end
23
+ end # describe "#preview" do
24
+
25
+ describe "XLSX export" do
26
+ render_views
27
+
28
+ it "should be ok" do
29
+ 3.times { create(:billing_machine_invoice_line) }
30
+ get :index, params: {format: :xlsx}
31
+ expect(response).to be_ok
32
+ end
33
+ end # describe "XLSX export"
34
+
35
+ describe "PDF export" do
36
+ render_views
37
+
38
+ it "should be ok" do
39
+ 3.times {
40
+ invoice = create(:billing_machine_invoice)
41
+ Dorsale::BillingMachine::PdfFileGenerator.(invoice)
42
+ }
43
+ get :index, params: {format: :pdf}
44
+ expect(response).to be_ok
45
+ end
46
+ end # describe "PDF export"
47
+
48
+ describe "filters" do
49
+ describe "filter by date" do
50
+ before do
51
+ Timecop.freeze "2016-11-08 12:00:00"
52
+ @today = create(:billing_machine_invoice, date: "2016-11-08")
53
+ @yesterday = create(:billing_machine_invoice, date: "2016-11-07")
54
+ @tomorrow = create(:billing_machine_invoice, date: "2016-11-09")
55
+ @last_week = create(:billing_machine_invoice, date: "2016-11-04")
56
+ @last_month = create(:billing_machine_invoice, date: "2016-10-18")
57
+ @last_year = create(:billing_machine_invoice, date: "2015-10-18")
58
+ end
59
+
60
+ def filter(period)
61
+ cookies[:filters] = {"bm_time_period" => period.to_s}.to_json
62
+ get :index
63
+ end
64
+
65
+ it "should filter by all_time" do
66
+ filter :all_time
67
+ expect(assigns :invoices).to contain_exactly(
68
+ @today,
69
+ @yesterday,
70
+ @tomorrow,
71
+ @last_week,
72
+ @last_month,
73
+ @last_year,
74
+ )
75
+ end
76
+
77
+ it "should filter by today" do
78
+ filter :today
79
+ expect(assigns :invoices).to contain_exactly(@today)
80
+ end
81
+
82
+ it "should filter by yesterday" do
83
+ filter :yesterday
84
+ expect(assigns :invoices).to contain_exactly(@yesterday)
85
+ end
86
+
87
+ it "should filter by this_week" do
88
+ filter :this_week
89
+ expect(assigns :invoices).to contain_exactly(@today, @yesterday, @tomorrow)
90
+ end
91
+
92
+ it "should filter by this_month" do
93
+ filter :this_month
94
+ expect(assigns :invoices).to contain_exactly(@today, @yesterday, @tomorrow, @last_week)
95
+ end
96
+
97
+ it "should filter by this_year" do
98
+ filter :this_year
99
+ expect(assigns :invoices).to \
100
+ contain_exactly(@today, @yesterday, @tomorrow, @last_week, @last_month)
101
+ end
102
+
103
+ it "should filter by last_week" do
104
+ filter :last_week
105
+ expect(assigns :invoices).to contain_exactly(@last_week)
106
+ end
107
+
108
+ it "should filter by last_month" do
109
+ filter :last_month
110
+ expect(assigns :invoices).to contain_exactly(@last_month)
111
+ end
112
+
113
+ it "should filter by last_year" do
114
+ filter :last_year
115
+ expect(assigns :invoices).to contain_exactly(@last_year)
116
+ end
117
+ end # describe "filter by date"
118
+
119
+ describe "filter by payment status" do
120
+ before do
121
+ Timecop.freeze "2016-11-08 12:00:00"
122
+ @paid = create(:billing_machine_invoice, paid: true, due_date: "2016-01-08")
123
+ @pending = create(:billing_machine_invoice, paid: false, due_date: "2016-11-10")
124
+ @late = create(:billing_machine_invoice, paid: false, due_date: "2016-06-05")
125
+ end
126
+
127
+ def filter(value)
128
+ cookies[:filters] = {"bm_payment_status" => value.to_s}.to_json
129
+ get :index
130
+ end
131
+
132
+ it "should filter by paid" do
133
+ filter :paid
134
+ expect(assigns :invoices).to contain_exactly(@paid)
135
+ end
136
+
137
+ it "should filter by unpaid" do
138
+ filter :unpaid
139
+ expect(assigns :invoices).to contain_exactly(@pending, @late)
140
+ end
141
+
142
+ it "should filter by pending" do
143
+ filter :pending
144
+ expect(assigns :invoices).to contain_exactly(@pending)
145
+ end
146
+
147
+ it "should filter by late" do
148
+ filter :late
149
+ expect(assigns :invoices).to contain_exactly(@late)
150
+ end
151
+ end # describe "filter by payment status"
152
+ end # describe "filters"
153
+ end
@@ -0,0 +1,24 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::BillingMachine::QuotationsController, type: :controller do
4
+ routes { Dorsale::Engine.routes }
5
+
6
+ let(:user) { create(:user) }
7
+ before(:each) { sign_in(user) }
8
+
9
+ describe "#preview" do
10
+ render_views
11
+
12
+ it "should render show" do
13
+ post :preview
14
+ expect(response).to render_template(:show)
15
+ end
16
+
17
+ it "should not save" do
18
+ post :preview
19
+ @quotation = assigns(:quotation)
20
+ expect(@quotation).to be_valid
21
+ expect(@quotation).to_not be_persisted
22
+ end
23
+ end # describe "#preview" do
24
+ end
@@ -0,0 +1,50 @@
1
+ require "rails_helper"
2
+
3
+ describe Dorsale::CommentsController, type: :controller do
4
+ routes { Dorsale::Engine.routes }
5
+
6
+ let(:user) { create(:user) }
7
+
8
+ before(:each) { sign_in(user) }
9
+
10
+ let(:commentable) { create(:customer_vault_corporation) }
11
+ let(:valid_params) {
12
+ {
13
+ :comment => {
14
+ :commentable_id => commentable.id,
15
+ :commentable_type => commentable.class.to_s,
16
+ :text => "Hello",
17
+ },
18
+ :back_url => "/",
19
+ }
20
+ }
21
+
22
+ describe "create" do
23
+ it "should create comment" do
24
+ post :create, params: valid_params
25
+ expect(assigns(:comment)).to be_persisted
26
+ end
27
+
28
+ it "should redirect to back_url" do
29
+ post :create, params: valid_params
30
+ expect(response).to redirect_to("/")
31
+ end
32
+ end
33
+
34
+ describe "update" do
35
+ it "should update comment text" do
36
+ comment = create(:dorsale_comment)
37
+ patch :update, params: {id: comment, comment: {text: "New-comment-text"}, back_url: "/"}
38
+ expect(response).to redirect_to("/")
39
+ expect(comment.reload.text).to eq "New-comment-text"
40
+ end
41
+ end
42
+
43
+ describe "destroy" do
44
+ it "should destroy comment" do
45
+ comment = create(:dorsale_comment)
46
+ delete :destroy, params: {id: comment, back_url: "/"}
47
+ expect(response).to redirect_to("/")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,42 @@
1
+ require "rails_helper"
2
+
3
+ describe ::Dorsale::CustomerVault::EventsController, type: :controller do
4
+ routes { Dorsale::Engine.routes }
5
+
6
+ let(:user) { create(:user) }
7
+
8
+ before(:each) { sign_in(user) }
9
+
10
+ describe "#filters" do
11
+ before do
12
+ @event1 = create(:customer_vault_event, action: "create")
13
+ @event2 = create(:customer_vault_event, action: "update")
14
+ end
15
+
16
+ it "should filter by event_action" do
17
+ cookies[:filters] = {event_action: "create"}.to_json
18
+ get :index
19
+ expect(assigns(:events)).to eq [@event1]
20
+ end
21
+
22
+ it "should filter by multiple event_action" do
23
+ cookies[:filters] = {event_action: "create update"}.to_json
24
+ get :index
25
+ expect(assigns(:events)).to contain_exactly(@event1, @event2)
26
+ end
27
+ end # describe "#filters"
28
+
29
+ describe "#index" do
30
+ before do
31
+ @corporation1 = create(:customer_vault_corporation)
32
+ @corporation2 = create(:customer_vault_corporation)
33
+ @event1 = create(:customer_vault_event, person: @corporation1, created_at: "2012-02-15")
34
+ @event2 = create(:customer_vault_event, person: @corporation2, created_at: "2012-03-15")
35
+ end
36
+
37
+ it "should assigns all events ordered by created_at DESC" do
38
+ get :index
39
+ expect(assigns(:events)).to eq [@event2, @event1]
40
+ end
41
+ end # describe "#index"
42
+ end
@@ -0,0 +1,129 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::CustomerVault::PeopleController, type: :controller do
4
+ routes { Dorsale::Engine.routes }
5
+
6
+ let(:user) { create(:user) }
7
+
8
+ before(:each) { sign_in(user) }
9
+
10
+ describe "#corporations" do
11
+ render_views
12
+
13
+ it "should return corporations only" do
14
+ corporation = create(:customer_vault_corporation)
15
+ individual = create(:customer_vault_individual)
16
+ get :corporations
17
+ expect(assigns :people).to eq [corporation]
18
+ end
19
+ end # describe "#corporations"
20
+
21
+ describe "#individuals" do
22
+ render_views
23
+
24
+ it "should return individuals only" do
25
+ corporation = create(:customer_vault_corporation)
26
+ individual = create(:customer_vault_individual)
27
+ get :individuals
28
+ expect(assigns :people).to eq [individual]
29
+ end
30
+ end # describe "#individuals"
31
+
32
+ describe "#list" do
33
+ describe "sorting" do
34
+ it "should sort people by name by default" do
35
+ abc = create(:customer_vault_corporation, name: "Abc Corp")
36
+ bob = create(:customer_vault_individual, last_name: "Bob")
37
+ alice = create(:customer_vault_individual, last_name: "Alice")
38
+ zorg = create(:customer_vault_corporation, name: "Zorg Corp")
39
+
40
+ get :index
41
+
42
+ expect(assigns(:people)).to eq([abc, alice, bob, zorg])
43
+ end
44
+ end # describe "sorting"
45
+
46
+ describe "filters" do
47
+ it "should filter by person type" do
48
+ individual = create(:customer_vault_individual)
49
+ corporation = create(:customer_vault_corporation)
50
+
51
+ cookies[:filters] = {person_type: "Dorsale::CustomerVault::Individual"}.to_json
52
+
53
+ get :index
54
+
55
+ expect(assigns(:people)).to eq [individual]
56
+ end
57
+
58
+ it "should filter by person origin" do
59
+ origin = create(:customer_vault_origin)
60
+ individual1 = create(:customer_vault_individual, origin: origin)
61
+ individual2 = create(:customer_vault_individual)
62
+
63
+ cookies[:filters] = {person_origin: origin.id}.to_json
64
+ get :index
65
+
66
+ expect(assigns(:people)).to eq [individual1]
67
+ end
68
+
69
+ it "should filter by person activity_type" do
70
+ activity_type = create(:customer_vault_activity_type)
71
+ corporation1 = create(:customer_vault_corporation, activity_type: activity_type)
72
+ corporation2 = create(:customer_vault_corporation)
73
+
74
+ cookies[:filters] = {person_activity: activity_type.id}.to_json
75
+ get :index
76
+
77
+ expect(assigns(:people)).to eq [corporation1]
78
+ end
79
+ end # describe "filters"
80
+
81
+ describe "search" do
82
+ it "search should ignore filters" do
83
+ corporation1 = create(:customer_vault_corporation, tag_list: "abc", name: "aaa")
84
+ corporation2 = create(:customer_vault_corporation, tag_list: "xyz", name: "bbb")
85
+ @request.cookies["filters"] = {tags: ["abc"]}.to_json
86
+ get :index, params: {q: "bbb"}
87
+ expect(assigns(:people)).to eq [corporation2]
88
+ end
89
+ end # describe "search"
90
+ end # describe "#list"
91
+
92
+ describe "#create" do
93
+ before do
94
+ allow_any_instance_of(Dorsale::CustomerVault::PeopleController).to \
95
+ receive(:model) { Dorsale::CustomerVault::Corporation }
96
+ end
97
+
98
+ it "should generate an event" do
99
+ expect {
100
+ post :create, params: {person: {corporation_name: "agilidée"}}
101
+ }.to change(Dorsale::CustomerVault::Event, :count).by(1)
102
+
103
+ event = Dorsale::CustomerVault::Event.last_created
104
+ expect(event.author).to eq user
105
+ expect(event.person).to eq Dorsale::CustomerVault::Person.last_created
106
+ expect(event.action).to eq "create"
107
+ end
108
+ end # describe "#create"
109
+
110
+ describe "#update" do
111
+ before do
112
+ allow_any_instance_of(Dorsale::CustomerVault::PeopleController).to \
113
+ receive(:model) { Dorsale::CustomerVault::Corporation }
114
+ end
115
+
116
+ it "should generate an event" do
117
+ corporation = create(:customer_vault_corporation)
118
+
119
+ expect {
120
+ patch :update, params: {id: corporation, person: {corporation_name: "agilidée"}}
121
+ }.to change(Dorsale::CustomerVault::Event, :count).by(1)
122
+
123
+ event = Dorsale::CustomerVault::Event.last_created
124
+ expect(event.author).to eq user
125
+ expect(event.person).to eq corporation
126
+ expect(event.action).to eq "update"
127
+ end
128
+ end # describe "#update"
129
+ end
@@ -0,0 +1,55 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ::Dorsale::ExpenseGun::ExpensesController, type: :controller do
4
+ routes { Dorsale::Engine.routes }
5
+ let(:user) { create(:user) }
6
+ before(:each) { sign_in(user) }
7
+
8
+ describe "#index" do
9
+ describe "filters" do
10
+ render_views
11
+
12
+ it "should filter by state" do
13
+ expense1 = create(:expense_gun_expense, state: "accepted")
14
+ expense2 = create(:expense_gun_expense, state: "refused")
15
+
16
+ cookies[:filters] = {expense_state: "accepted"}.to_json
17
+ get :index
18
+
19
+ expect(assigns :expenses).to eq [expense1]
20
+ end
21
+
22
+ it "should filter by user" do
23
+ user1 = create(:user)
24
+ user2 = create(:user)
25
+ expense1 = create(:expense_gun_expense, user: user1)
26
+ expense2 = create(:expense_gun_expense, user: user2)
27
+
28
+ cookies[:filters] = {expense_user_id: user1.id}.to_json
29
+ get :index
30
+
31
+ expect(assigns :expenses).to eq [expense1]
32
+ end
33
+
34
+ it "should assigns only users having expenses" do
35
+ user1 = create(:user)
36
+ user2 = create(:user)
37
+ expense2 = create(:expense_gun_expense, user: user2)
38
+
39
+ get :index
40
+
41
+ expect(assigns :users).to eq [user2]
42
+ end
43
+ end # describe "filters"
44
+ end # describe "#index"
45
+
46
+ describe "#show" do
47
+ render_views
48
+
49
+ it "should be ok as PDF" do
50
+ expense = create(:expense_gun_expense, user: user)
51
+ get :show, params: {id: expense, format: :pdf}
52
+ expect(response).to be_ok
53
+ end
54
+ end # describe "#show"
55
+ end