bookkeeper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/app/controllers/bookkeeper/search_controller.rb +11 -0
- data/app/models/bookkeeper/purchase.rb +2 -0
- data/app/views/bookkeeper/purchases/_search.html.erb +6 -0
- data/app/views/bookkeeper/purchases/index.html.erb +3 -0
- data/app/views/bookkeeper/search/create.html.erb +31 -0
- data/config/locales/en.yml +6 -0
- data/config/routes.rb +1 -0
- data/lib/bookkeeper/version.rb +1 -1
- data/spec/controllers/bookkeeper/purchases_controller_spec.rb +38 -34
- data/spec/controllers/bookkeeper/search_controller_spec.rb +33 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +6237 -0
- metadata +8 -45
- data/spec/dummy/public/uploads/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-0153/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-0153/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-1009/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-1009/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-2120/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-2120/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-2714/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-2714/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-3081/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-3081/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-3658/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-3658/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-5761/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-5761/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-6301/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-6301/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-8404/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-8404/thumb_receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-9318/receipt.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/20130223-1958-61501-9318/thumb_receipt.jpg +0 -0
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Bookkeeper
|
1
|
+
# Bookkeeper [![Build Status](https://secure.travis-ci.org/tommyblue/Bookkeeper.png?branch=master)](http://travis-ci.org/tommyblue/Bookkeeper) [![Dependency Status](https://gemnasium.com/tommyblue/Bookkeeper.png)](https://gemnasium.com/tommyblue/Bookkeeper) [![Code Climate](https://codeclimate.com/github/tommyblue/Bookkeeper.png)](https://codeclimate.com/github/tommyblue/Bookkeeper)
|
2
2
|
|
3
3
|
Bookkeeper is a Rails engine with the aim of allowing a Rails application (at least 3.1) to handle the purchases you made and their receipt.
|
4
4
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_dependency "bookkeeper/application_controller"
|
2
|
+
|
3
|
+
module Bookkeeper
|
4
|
+
class SearchController < ApplicationController
|
5
|
+
def create
|
6
|
+
@q = params[:search][:q]
|
7
|
+
query = "%#{@q}%"
|
8
|
+
@results = Purchase.where("title LIKE ? OR description LIKE ?", query, query)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
<%= render partial: 'search' %>
|
1
2
|
<h1><%= t '.title' %></h1>
|
2
3
|
|
3
4
|
<table class='table table-striped table-condensed table-bordered'>
|
@@ -8,6 +9,7 @@
|
|
8
9
|
<th><%=t 'bookkeeper.models.purchase.attributes.purchase_date' %></th>
|
9
10
|
<th><%=t 'bookkeeper.models.purchase.attributes.warranty_duration' %></th>
|
10
11
|
<th><%=t 'bookkeeper.models.purchase.attributes.receipt' %></th>
|
12
|
+
<th><%=t 'bookkeeper.models.purchase.attributes.updated_at' %></th>
|
11
13
|
<th></th>
|
12
14
|
</tr>
|
13
15
|
</thead>
|
@@ -19,6 +21,7 @@
|
|
19
21
|
<td><%=l purchase.purchase_date rescue '' %></td>
|
20
22
|
<td><%= purchase.warranty_duration %> <%=t '.months' %></td>
|
21
23
|
<td><%= link_to "<i class='icon-download-alt'></i> #{purchase.receipt.file.filename}".html_safe, purchase.receipt.url, class: 'btn btn-mini' if purchase.receipt.file %></td>
|
24
|
+
<td><%=l purchase.updated_at, format: :short rescue '' %></td>
|
22
25
|
<td>
|
23
26
|
<%= link_to ('<i class="icon-pencil"></i> ' + t('bookkeeper.actions.edit')).html_safe, edit_purchase_path(purchase), class: 'btn btn-mini' %>
|
24
27
|
<%= link_to ('<i class="icon-remove"></i> ' + t('bookkeeper.actions.destroy')).html_safe, purchase, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-mini btn-danger' %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<h1><%= t '.title', q: @q %></h1>
|
2
|
+
|
3
|
+
<table class='table table-striped table-condensed table-bordered'>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th><%=t 'bookkeeper.models.purchase.attributes.title' %></th>
|
7
|
+
<th><%=t 'bookkeeper.models.purchase.attributes.description' %></th>
|
8
|
+
<th><%=t 'bookkeeper.models.purchase.attributes.purchase_date' %></th>
|
9
|
+
<th><%=t 'bookkeeper.models.purchase.attributes.warranty_duration' %></th>
|
10
|
+
<th><%=t 'bookkeeper.models.purchase.attributes.receipt' %></th>
|
11
|
+
<th></th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
<tbody>
|
15
|
+
<% @results.each do |purchase| %>
|
16
|
+
<tr>
|
17
|
+
<td><%= purchase.title %></td>
|
18
|
+
<td><%= purchase.description %></td>
|
19
|
+
<td><%=l purchase.purchase_date rescue '' %></td>
|
20
|
+
<td><%= purchase.warranty_duration %> <%=t '.months' %></td>
|
21
|
+
<td><%= link_to "<i class='icon-download-alt'></i> #{purchase.receipt.file.filename}".html_safe, purchase.receipt.url, class: 'btn btn-mini' if purchase.receipt.file %></td>
|
22
|
+
<td>
|
23
|
+
<%= link_to ('<i class="icon-pencil"></i> ' + t('bookkeeper.actions.edit')).html_safe, edit_purchase_path(purchase), class: 'btn btn-mini' %>
|
24
|
+
<%= link_to ('<i class="icon-remove"></i> ' + t('bookkeeper.actions.destroy')).html_safe, purchase, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-mini btn-danger' %>
|
25
|
+
</td>
|
26
|
+
</tr>
|
27
|
+
<% end %>
|
28
|
+
</tbody>
|
29
|
+
</table>
|
30
|
+
<br />
|
31
|
+
<%= link_to ('<i class="icon-arrow-left"></i> ' + t('bookkeeper.actions.back')).html_safe, purchases_path, class: 'btn' %>
|
data/config/locales/en.yml
CHANGED
@@ -17,6 +17,7 @@ en:
|
|
17
17
|
purchase_date: 'Purchase date'
|
18
18
|
warranty_duration: 'Warranty duration'
|
19
19
|
receipt: 'Receipt'
|
20
|
+
updated_at: 'Last update'
|
20
21
|
# controllers
|
21
22
|
controllers:
|
22
23
|
purchases:
|
@@ -24,6 +25,9 @@ en:
|
|
24
25
|
updated: 'Purchase was successfully updated.'
|
25
26
|
destroyed: 'Purchase was successfully deleted.'
|
26
27
|
# views
|
28
|
+
search:
|
29
|
+
create:
|
30
|
+
title: 'Search results for "%{q}"'
|
27
31
|
purchases:
|
28
32
|
index:
|
29
33
|
title: 'Listing purchases'
|
@@ -32,3 +36,5 @@ en:
|
|
32
36
|
title: 'New purchase'
|
33
37
|
edit:
|
34
38
|
title: 'Edit purchase'
|
39
|
+
search:
|
40
|
+
search: 'Search'
|
data/config/routes.rb
CHANGED
data/lib/bookkeeper/version.rb
CHANGED
@@ -2,46 +2,50 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Bookkeeper
|
4
4
|
describe PurchasesController do
|
5
|
-
def valid_session
|
6
|
-
{}
|
7
|
-
end
|
8
|
-
|
9
5
|
describe "GET index" do
|
10
6
|
it "assigns all purchases as @purchases" do
|
11
7
|
purchase = create(:bookkeeper_purchase)
|
12
|
-
get :index, { use_route: :purchases }
|
8
|
+
get :index, { use_route: :purchases }
|
13
9
|
expect(assigns(:purchases)).to match_array [purchase]
|
14
10
|
end
|
15
11
|
|
16
12
|
it "renders the :index template" do
|
17
13
|
purchase = create(:bookkeeper_purchase)
|
18
|
-
get :index, { use_route: :purchases }
|
14
|
+
get :index, { use_route: :purchases }
|
19
15
|
expect(response).to render_template :index
|
20
16
|
end
|
21
|
-
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
get :
|
27
|
-
expect(assigns(:
|
18
|
+
it "shows all purchases ordered by creation" do
|
19
|
+
first_purchase = create(:bookkeeper_purchase)
|
20
|
+
last_purchase = create(:bookkeeper_purchase)
|
21
|
+
get :index, { use_route: :purchases }
|
22
|
+
expect(assigns(:purchases)).to eq([last_purchase, first_purchase])
|
28
23
|
end
|
29
24
|
|
30
|
-
it "renders the :show template" do
|
31
|
-
purchase = create(:bookkeeper_purchase)
|
32
|
-
get :show, { id: purchase.to_param, use_route: :purchases }, valid_session
|
33
|
-
expect(response).to render_template :show
|
34
|
-
end
|
35
25
|
end
|
36
26
|
|
27
|
+
# describe "GET show" do
|
28
|
+
# it "assigns the requested purchase as @purchase" do
|
29
|
+
# purchase = create(:bookkeeper_purchase)
|
30
|
+
# get :show, { id: purchase.to_param, use_route: :purchases }
|
31
|
+
# expect(assigns(:purchase)).to eq purchase
|
32
|
+
# end
|
33
|
+
|
34
|
+
# it "renders the :show template" do
|
35
|
+
# purchase = create(:bookkeeper_purchase)
|
36
|
+
# get :show, { id: purchase.to_param, use_route: :purchases }
|
37
|
+
# expect(response).to render_template :show
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
|
37
41
|
describe "GET new" do
|
38
42
|
it "assigns a new purchase as @purchase" do
|
39
|
-
get :new, { use_route: :purchases }
|
43
|
+
get :new, { use_route: :purchases }
|
40
44
|
expect(assigns(:purchase)).to be_a_new(Purchase)
|
41
45
|
end
|
42
46
|
|
43
47
|
it "renders the :new template" do
|
44
|
-
get :new, { use_route: :purchases }
|
48
|
+
get :new, { use_route: :purchases }
|
45
49
|
expect(response).to render_template :new
|
46
50
|
end
|
47
51
|
end
|
@@ -49,13 +53,13 @@ module Bookkeeper
|
|
49
53
|
describe "GET edit" do
|
50
54
|
it "assigns the requested purchase as @purchase" do
|
51
55
|
purchase = create(:bookkeeper_purchase)
|
52
|
-
get :edit, { id: purchase.to_param, use_route: :purchases }
|
56
|
+
get :edit, { id: purchase.to_param, use_route: :purchases }
|
53
57
|
expect(assigns(:purchase)).to eq(purchase)
|
54
58
|
end
|
55
59
|
|
56
60
|
it "renders the :edit template" do
|
57
61
|
purchase = create(:bookkeeper_purchase)
|
58
|
-
get :edit, { id: purchase.to_param, use_route: :purchases }
|
62
|
+
get :edit, { id: purchase.to_param, use_route: :purchases }
|
59
63
|
expect(response).to render_template :edit
|
60
64
|
end
|
61
65
|
end
|
@@ -64,18 +68,18 @@ module Bookkeeper
|
|
64
68
|
describe "with valid params" do
|
65
69
|
it "creates a new Purchase" do
|
66
70
|
expect {
|
67
|
-
post :create, {purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
71
|
+
post :create, {purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
68
72
|
}.to change(Purchase, :count).by(1)
|
69
73
|
end
|
70
74
|
|
71
75
|
it "assigns a newly created purchase as @purchase" do
|
72
|
-
post :create, {purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
76
|
+
post :create, {purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
73
77
|
expect(assigns(:purchase)).to be_a(Purchase)
|
74
78
|
expect(assigns(:purchase)).to be_persisted
|
75
79
|
end
|
76
80
|
|
77
81
|
it "redirects to the purchases page" do
|
78
|
-
post :create, {purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
82
|
+
post :create, {purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
79
83
|
expect(response).to redirect_to :purchases
|
80
84
|
end
|
81
85
|
end
|
@@ -83,17 +87,17 @@ module Bookkeeper
|
|
83
87
|
describe "with invalid params" do
|
84
88
|
it "does not save the new Purchase" do
|
85
89
|
expect {
|
86
|
-
post :create, {purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
90
|
+
post :create, {purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
87
91
|
}.to_not change(Purchase, :count).by(1)
|
88
92
|
end
|
89
93
|
|
90
94
|
it "assigns a newly created but unsaved purchase as @purchase" do
|
91
|
-
post :create, {purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
95
|
+
post :create, {purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
92
96
|
expect(assigns(:purchase)).to be_a_new(Purchase)
|
93
97
|
end
|
94
98
|
|
95
99
|
it "re-renders the 'new' template" do
|
96
|
-
post :create, {purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
100
|
+
post :create, {purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
97
101
|
expect(response).to render_template :new
|
98
102
|
end
|
99
103
|
end
|
@@ -107,30 +111,30 @@ module Bookkeeper
|
|
107
111
|
|
108
112
|
describe "with valid params" do
|
109
113
|
it "updates the requested purchase" do
|
110
|
-
put :update, {id: @purchase, use_route: :purchases, purchase: attributes_for(:bookkeeper_purchase)}
|
114
|
+
put :update, {id: @purchase, use_route: :purchases, purchase: attributes_for(:bookkeeper_purchase)}
|
111
115
|
expect(assigns(:purchase)).to eq(@purchase)
|
112
116
|
end
|
113
117
|
|
114
118
|
it "assigns the requested purchase as @purchase" do
|
115
|
-
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
119
|
+
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
116
120
|
expect(assigns(:purchase)).to eq(@purchase)
|
117
121
|
end
|
118
122
|
|
119
123
|
it "redirects to the purchase" do
|
120
|
-
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
124
|
+
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_purchase), use_route: :purchases}
|
121
125
|
expect(response).to redirect_to(:purchases)
|
122
126
|
end
|
123
127
|
end
|
124
128
|
|
125
129
|
describe "with invalid params" do
|
126
130
|
it "assigns the purchase as @purchase" do
|
127
|
-
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
131
|
+
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
128
132
|
@purchase.reload
|
129
133
|
expect(@purchase.title).to eq(@purchase_title)
|
130
134
|
end
|
131
135
|
|
132
136
|
it "re-renders the 'edit' template" do
|
133
|
-
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
137
|
+
put :update, {id: @purchase.to_param, purchase: attributes_for(:bookkeeper_invalid_purchase), use_route: :purchases}
|
134
138
|
expect(response).to render_template :edit
|
135
139
|
end
|
136
140
|
end
|
@@ -142,12 +146,12 @@ module Bookkeeper
|
|
142
146
|
end
|
143
147
|
it "destroys the requested purchase" do
|
144
148
|
expect {
|
145
|
-
delete :destroy, {id: @purchase.to_param, use_route: :purchases}
|
149
|
+
delete :destroy, {id: @purchase.to_param, use_route: :purchases}
|
146
150
|
}.to change(Purchase, :count).by(-1)
|
147
151
|
end
|
148
152
|
|
149
153
|
it "redirects to the purchases list" do
|
150
|
-
delete :destroy, {id: @purchase.to_param, use_route: :purchases}
|
154
|
+
delete :destroy, {id: @purchase.to_param, use_route: :purchases}
|
151
155
|
expect(response).to redirect_to :purchases
|
152
156
|
end
|
153
157
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Bookkeeper
|
4
|
+
describe SearchController do
|
5
|
+
describe "POST create" do
|
6
|
+
describe "with search results" do
|
7
|
+
it "assigns the researched term as @q" do
|
8
|
+
post :create, {search: {q: 'searchable'}, use_route: :purchases}
|
9
|
+
expect(assigns(:q)).to eq('searchable')
|
10
|
+
end
|
11
|
+
it "Finds the purchase by title" do
|
12
|
+
purchase = create(:bookkeeper_purchase, title: 'My searchable purchase')
|
13
|
+
post :create, {search: {q: 'searchable'}, use_route: :purchases}
|
14
|
+
expect(assigns(:results)).to eq([purchase])
|
15
|
+
end
|
16
|
+
it "Finds the purchase by description" do
|
17
|
+
purchase = create(:bookkeeper_purchase, description: 'My searchable purchase')
|
18
|
+
post :create, {search: {q: 'searchable'}, use_route: :purchases}
|
19
|
+
expect(assigns(:results)).to eq([purchase])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "without search results" do
|
24
|
+
it "Doesn't find the purchase" do
|
25
|
+
purchase = create(:bookkeeper_purchase, title: 'My searchable purchase')
|
26
|
+
post :create, {search: {q: 'unsearchable'}, use_route: :purchases}
|
27
|
+
expect(assigns(:results)).to eq([])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
File without changes
|