Skip to content

Commit a9188ab

Browse files
committed
get rubocopped
1 parent c7abeb1 commit a9188ab

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ See the `Makefile` for all commands.
4848
Run `bundle exec rake`\
4949
or if that doesn't work try `bundle exec rspec`?
5050
51+
#### Linter (rubocop)
52+
- Run `bundle exec rubocop` to lint
53+
- To autocorrect most offences
54+
- safely : `bundle exec rubocop -a`
55+
- unsafely : `bundle exec rubocop -A`
56+
5157
## Deploy to production
5258
5359
1. Make sure your user has access to tap@tap.zeus.gent.

app/controllers/users_controller.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ def quick_order
108108
product = Product.find_by(id: params[:product_id])
109109

110110
unless product
111-
flash[:error] = "Product not found!"
111+
flash.now[:error] = "Product not found!"
112112
respond_to do |format|
113113
format.html { redirect_back_or_to(root_path) }
114-
format.json { render json: { message: "Quick order failed for #{@user.name}. Product not found." }, status: :bad_request }
114+
format.json do
115+
render json: { message: "Quick order failed for #{@user.name}. Product not found." }, status: :bad_request
116+
end
115117
end
116118
return
117119
end
@@ -135,9 +137,11 @@ def quick_order
135137
flash[:error] = order.valid? ? "Something went wrong! Please try again." : order.errors.full_messages.join(". ")
136138
respond_to do |format|
137139
format.html { redirect_back_or_to(root_path) }
138-
format.json { render json: {
139-
message: order.errors.full_messages.join(". ")
140-
}, status: :unprocessable_entity }
140+
format.json do
141+
render json: {
142+
message: order.errors.full_messages.join(". ")
143+
}, status: :unprocessable_content
144+
end
141145
end
142146
end
143147
end

app/models/user.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def balance
109109

110110
def last_ordered_products(amount = 5)
111111
orders.includes(:products)
112-
.order(created_at: :desc)
113-
.limit(amount)
114-
.flat_map(&:products)
115-
.uniq
116-
.first(amount)
112+
.order(created_at: :desc)
113+
.limit(amount)
114+
.flat_map(&:products)
115+
.uniq
116+
.first(amount)
117117
end
118118

119119
# Static Users

spec/controllers/users_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
context "with an invalid product_id" do
226226
it "does not create an order" do
227227
expect do
228-
post :quick_order, params: { id: user.id, product_id: 99999 }
228+
post :quick_order, params: { id: user.id, product_id: 99_999 }
229229
end.not_to change(Order, :count)
230230
end
231231
end

0 commit comments

Comments
 (0)