Skip to content

Commit

Permalink
use uuid as primary key for Basket
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Feb 28, 2019
1 parent 270d701 commit 6b55baf
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion app/models/checked_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def check_due_date
#
# id :bigint(8) not null, primary key
# item_id :uuid not null
# basket_id :bigint(8) not null
# basket_id :uuid not null
# librarian_id :bigint(8)
# due_date :datetime not null
# created_at :datetime not null
Expand Down
2 changes: 1 addition & 1 deletion app/models/checkin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def set_checkout
# id :bigint(8) not null, primary key
# item_id :uuid not null
# librarian_id :bigint(8)
# basket_id :bigint(8)
# basket_id :uuid
# created_at :datetime not null
# updated_at :datetime not null
# lock_version :integer default(0), not null
Expand Down
2 changes: 1 addition & 1 deletion app/models/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def self.remove_all_history(user)
# item_id :uuid not null
# checkin_id :bigint(8)
# librarian_id :bigint(8)
# basket_id :bigint(8)
# basket_id :uuid
# due_date :datetime
# checkout_renewal_count :integer default(0), not null
# lock_version :integer default(0), not null
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/032_create_checkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def change
create_table :checkins do |t|
t.references :item, foreign_key: true, null: false, type: :uuid
t.references :librarian, index: true
t.references :basket, index: true
t.references :basket, index: true, type: :uuid
t.timestamps
end
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/033_create_checkouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def change
t.references :item, foreign_key: true, null: false, type: :uuid
t.references :checkin, foreign_key: true
t.references :librarian, foreign_key: {to_table: :users}
t.references :basket, index: true
t.references :basket, index: true, type: :uuid
t.datetime :due_date
t.integer :checkout_renewal_count, default: 0, null: false
t.integer :lock_version, default: 0, null: false
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/121_create_checked_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreateCheckedItems < ActiveRecord::Migration[5.2]
def change
create_table :checked_items do |t|
t.references :item, foreign_key: true, null: false, type: :uuid
t.references :basket, foreign_key: true, null: false
t.references :basket, foreign_key: true, null: false, type: :uuid
t.references :librarian, index: true
t.datetime :due_date, null: false

Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/accepts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mock_user(stubs = {})

describe 'When basket_id is specified' do
it 'assigns all accepts as @accepts' do
get :index, params: { basket_id: 10 }
get :index, params: { basket_id: baskets(:basket_00010).id }
assigns(:accepts).should eq baskets(:basket_00010).accepts.order('accepts.created_at DESC').page(1)
response.should be_successful
end
Expand All @@ -39,7 +39,7 @@ def mock_user(stubs = {})

describe 'When basket_id is specified' do
it 'assigns all accepts as @accepts' do
get :index, params: { basket_id: 9 }
get :index, params: { basket_id: baskets(:basket_00009).id }
assigns(:accepts).should eq baskets(:basket_00009).accepts.order('accepts.created_at DESC').page(1)
response.should be_successful
end
Expand Down Expand Up @@ -159,7 +159,7 @@ def mock_user(stubs = {})

describe 'When basket_id is specified' do
it 'redirects to the created accept' do
post :create, params: { accept: @attrs, basket_id: 9 }
post :create, params: { accept: @attrs, basket_id: baskets(:basket_00009).id }
response.should redirect_to(accepts_url(basket_id: assigns(:accept).basket.id))
assigns(:accept).item.circulation_status.name.should eq 'Available On Shelf'
end
Expand All @@ -179,7 +179,7 @@ def mock_user(stubs = {})
end

it 'should not create accept without item_id' do
post :create, params: { accept: { item_identifier: nil }, basket_id: 9 }
post :create, params: { accept: { item_identifier: nil }, basket_id: baskets(:basket_00009).id }
assigns(:accept).should_not be_valid
response.should be_successful
end
Expand Down
30 changes: 15 additions & 15 deletions spec/controllers/baskets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,34 @@
login_fixture_admin

it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
assigns(:basket).should eq(baskets(:basket_00001))
end
end

describe 'When logged in as Librarian' do
login_fixture_librarian

it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
assigns(:basket).should eq(baskets(:basket_00001))
end
end

describe 'When logged in as User' do
login_fixture_user

it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
assigns(:basket).should eq(baskets(:basket_00001))
response.should be_forbidden
end
end

describe 'When not logged in' do
it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
assigns(:basket).should eq(baskets(:basket_00001))
response.should redirect_to(new_user_session_url)
end
end
Expand Down Expand Up @@ -311,11 +311,11 @@

describe 'with valid params' do
it 'updates the requested basket' do
put :update, params: { id: 8, basket: @attrs }
put :update, params: { id: baskets(:basket_00008).id, basket: @attrs }
end

it 'assigns the requested basket as @basket' do
put :update, params: { id: 8, basket: @attrs }
put :update, params: { id: baskets(:basket_00008).id, basket: @attrs }
assigns(:basket).checkouts.order('created_at DESC').first.item.circulation_status.name.should eq 'On Loan'
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
Expand All @@ -332,12 +332,12 @@
login_fixture_admin

it 'should destroy basket without user_id' do
delete :destroy, params: { id: 1, basket: { user_id: nil }, user_id: users(:user1).username }
delete :destroy, params: { id: baskets(:basket_00001).id, basket: { user_id: nil }, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end

it 'should destroy basket' do
delete :destroy, params: { id: 1, basket: {}, user_id: users(:user1).username }
delete :destroy, params: { id: baskets(:basket_00001).id, basket: {}, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
end
Expand All @@ -346,12 +346,12 @@
login_fixture_librarian

it 'should destroy basket without user_id' do
delete :destroy, params: { id: 1, basket: { user_id: nil }, user_id: users(:user1).username }
delete :destroy, params: { id: baskets(:basket_00001).id, basket: { user_id: nil }, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end

it 'should destroy basket' do
delete :destroy, params: { id: 1, basket: {}, user_id: users(:user1).username }
delete :destroy, params: { id: baskets(:basket_00001).id, basket: {}, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
end
Expand All @@ -360,7 +360,7 @@
login_fixture_user

it 'should not destroy basket' do
delete :destroy, params: { id: 3, user_id: users(:user1).username }
delete :destroy, params: { id: baskets(:basket_00003).id, user_id: users(:user1).username }
response.should be_forbidden
end
end
Expand Down
44 changes: 22 additions & 22 deletions spec/controllers/checked_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

describe 'When basket is specified' do
it 'assigns checked_items as @checked_items' do
get :index, params: { basket_id: 1 }
get :index, params: { basket_id: baskets(:basket_00001).id }
assigns(:checked_items).should_not be_empty
response.should be_successful
end
Expand Down Expand Up @@ -113,7 +113,7 @@
login_fixture_admin

it 'assigns the requested checked_item as @checked_item' do
get :new, params: { basket_id: 3 }
get :new, params: { basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should_not be_valid
end

Expand All @@ -129,7 +129,7 @@
login_fixture_librarian

it 'assigns the requested checked_item as @checked_item' do
get :new, params: { basket_id: 3 }
get :new, params: { basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should_not be_valid
response.should be_successful
end
Expand All @@ -139,15 +139,15 @@
login_fixture_user

it 'should not assign the requested checked_item as @checked_item' do
get :new, params: { basket_id: 3 }
get :new, params: { basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should be_nil
response.should be_forbidden
end
end

describe 'When not logged in' do
it 'should not assign the requested checked_item as @checked_item' do
get :new, params: { basket_id: 3 }
get :new, params: { basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should be_nil
response.should redirect_to(new_user_session_url)
end
Expand Down Expand Up @@ -206,23 +206,23 @@

describe 'When the item is missing' do
it 'assigns a newly created checked_item as @checked_item' do
post :create, params: { checked_item: { item_identifier: 'not found' }, basket_id: 1 }
post :create, params: { checked_item: { item_identifier: 'not found' }, basket_id: baskets(:basket_00001).id }
assigns(:checked_item).should_not be_valid
assigns(:checked_item).errors[:base].include?(I18n.t('activerecord.errors.messages.checked_item.item_not_found')).should be_truthy
end
end

describe 'When the item is not for checkout' do
it 'assigns a newly created checked_item as @checked_item' do
post :create, params: { checked_item: { item_identifier: '00017' }, basket_id: 1 }
post :create, params: { checked_item: { item_identifier: '00017' }, basket_id: baskets(:basket_00001).id }
assigns(:checked_item).should_not be_valid
assigns(:checked_item).errors[:base].include?(I18n.t('activerecord.errors.messages.checked_item.not_available_for_checkout')).should be_truthy
end
end

describe 'When the item is already checked out' do
it 'assigns a newly created checked_item as @checked_item' do
post :create, params: { checked_item: { item_identifier: '00013' }, basket_id: 8 }
post :create, params: { checked_item: { item_identifier: '00013' }, basket_id: baskets(:basket_00008).id }
assigns(:checked_item).should_not be_valid
assigns(:checked_item).errors[:base].include?(I18n.t('activerecord.errors.messages.checked_item.already_checked_out')).should be_truthy
end
Expand All @@ -231,7 +231,7 @@
describe 'When the item is reserved' do
it 'assigns a newly created checked_item as @checked_item' do
old_count = items(:item_00021).manifestation.reserves.waiting.count
post :create, params: { checked_item: { item_identifier: '00021' }, basket_id: 11 }
post :create, params: { checked_item: { item_identifier: '00021' }, basket_id: baskets(:basket_00011).id }
assigns(:checked_item).should be_valid
assigns(:checked_item).item.manifestation.reserves.waiting.count.should eq old_count
assigns(:checked_item).librarian.should eq users(:admin)
Expand All @@ -244,7 +244,7 @@
end

it 'should not create checked_item without item_id' do
post :create, params: { checked_item: { item_identifier: '00004' }, basket_id: 1 }
post :create, params: { checked_item: { item_identifier: '00004' }, basket_id: baskets(:basket_00001).id }
response.should be_successful
end
end
Expand All @@ -253,47 +253,47 @@
login_fixture_librarian

it 'should create checked_item' do
post :create, params: { checked_item: @attrs, basket_id: 3 }
post :create, params: { checked_item: @attrs, basket_id: baskets(:basket_00003).id }
assigns(:checked_item).due_date.to_s.should eq Time.zone.now.tomorrow.end_of_day.to_s
response.should redirect_to checked_items_url(basket_id: assigns(:checked_item).basket_id)
end

it 'should create checked_item with item_identifier' do
post :create, params: { checked_item: { item_identifier: '00011' }, basket_id: 3 }
post :create, params: { checked_item: { item_identifier: '00011' }, basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should be_truthy
assigns(:checked_item).due_date.should_not be_nil
response.should redirect_to checked_items_url(basket_id: assigns(:checked_item).basket_id)
end

it 'should override due_date' do
post :create, params: { checked_item: { item_identifier: '00011', due_date_string: 1.year.from_now.strftime('%Y-%m-%d') }, basket_id: 3 }
post :create, params: { checked_item: { item_identifier: '00011', due_date_string: 1.year.from_now.strftime('%Y-%m-%d') }, basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should be_truthy
assigns(:checked_item).due_date.to_s.should eq 1.year.from_now.end_of_day.to_s
response.should redirect_to checked_items_url(basket_id: assigns(:checked_item).basket_id)
end

it 'should not create checked_item with an invalid due_date' do
post :create, params: { checked_item: { item_identifier: '00011', due_date_string: 'invalid' }, basket_id: 3 }
post :create, params: { checked_item: { item_identifier: '00011', due_date_string: 'invalid' }, basket_id: baskets(:basket_00003).id }
assigns(:checked_item).should_not be_valid
assigns(:checked_item).due_date.should be_nil
response.should be_successful
end

it 'should not create checked_item if excessed checkout_limit' do
post :create, params: { checked_item: { item_identifier: '00011' }, basket_id: 1 }
post :create, params: { checked_item: { item_identifier: '00011' }, basket_id: baskets(:basket_00001).id }
response.should be_successful
assigns(:checked_item).errors['base'].include?(I18n.t('activerecord.errors.messages.checked_item.excessed_checkout_limit')).should be_truthy
end

it 'should show message when the item includes supplements' do
post :create, params: { checked_item: { item_identifier: '00006' }, basket_id: 3 }
post :create, params: { checked_item: { item_identifier: '00006' }, basket_id: baskets(:basket_00003).id }
assigns(:checked_item).due_date.should_not be_nil
response.should redirect_to checked_items_url(basket_id: assigns(:checked_item).basket_id)
flash[:message].index(I18n.t('item.this_item_include_supplement')).should be_truthy
end

it 'should create checked_item when ignore_restriction is checked' do
post :create, params: { checked_item: { item_identifier: '00011', ignore_restriction: '1' }, basket_id: 2 }
post :create, params: { checked_item: { item_identifier: '00011', ignore_restriction: '1' }, basket_id: baskets(:basket_00002).id }
assigns(:checked_item).due_date.should_not be_nil
response.should redirect_to checked_items_url(basket_id: assigns(:checked_item).basket_id)
end
Expand All @@ -303,14 +303,14 @@
login_fixture_user

it 'should not create checked_item' do
post :create, params: { checked_item: { item_identifier: '00004' }, basket_id: 3 }
post :create, params: { checked_item: { item_identifier: '00004' }, basket_id: baskets(:basket_00003).id }
response.should be_forbidden
end
end

describe 'When not logged in as' do
it 'should not create checked_item' do
post :create, params: { checked_item: { item_identifier: '00004' }, basket_id: 1 }
post :create, params: { checked_item: { item_identifier: '00004' }, basket_id: baskets(:basket_00001).id }
response.should redirect_to new_user_session_url
end
end
Expand Down Expand Up @@ -340,7 +340,7 @@
end

it 'should update checked_item' do
put :update, params: { id: 4, checked_item: {}, basket_id: 8 }
put :update, params: { id: 4, checked_item: {}, basket_id: baskets(:basket_00008).id }
assigns(:checked_item).should be_valid
response.should redirect_to checked_item_url(assigns(:checked_item))
end
Expand All @@ -350,14 +350,14 @@
login_fixture_user

it 'should not update checked_item' do
put :update, params: { id: 1, checked_item: {}, basket_id: 3 }
put :update, params: { id: 1, checked_item: {}, basket_id: baskets(:basket_00003).id }
response.should be_forbidden
end
end

describe 'When not logged in' do
it 'should not update checked_item' do
put :update, params: { id: 1, checked_item: {}, basket_id: 1 }
put :update, params: { id: 1, checked_item: {}, basket_id: baskets(:basket_00001).id }
response.should redirect_to new_user_session_url
end
end
Expand Down
Loading

0 comments on commit 6b55baf

Please sign in to comment.