Skip to content

Commit

Permalink
fix #13 (#194)
Browse files Browse the repository at this point in the history
* fix #13

* ereased double request_return function
  • Loading branch information
AlexanderUngefug authored Dec 16, 2022
1 parent 813c986 commit 5f4c671
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
13 changes: 0 additions & 13 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,6 @@ def request_return
redirect_to item_url(@item)
end

def request_return
@item = Item.find(params[:id])
@item.set_status_pending_return
@item.save
@user = current_user
unless ReturnRequestNotification.find_by(item: @item)
@notification = ReturnRequestNotification.new(user: User.find(@item.owner),
date: Time.zone.now, item: @item, borrower: @user)
@notification.save
end
redirect_to item_url(@item)
end

def accept_return
@item = Item.find(params[:id])
@notification = ReturnRequestNotification.find_by(item: @item)
Expand Down
6 changes: 3 additions & 3 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions spec/features/request/accept_lend_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "rails_helper"

describe "Requests handling", type: :feature do

it "owner can start lending by accepting the request" do
owner = create(:max)
borrower = create(:peter)
item = create(:item, owner: owner.id)
sign_in borrower
visit item_path(item)
click_button('Lend')
expect(item.reload.lend_status).to eq('pending_lend_request')
sign_in owner
visit notifications_path
click_button('Check')
click_button('Accept')
expect(item.reload.lend_status).to eq('lent')
end
end

0 comments on commit 5f4c671

Please sign in to comment.