Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/controllers/reserves_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,22 @@ def show
def new
@reserve = Reserve.new

if current_user.has_role?('Librarian')
@reserve.user = @user
if current_user.has_role?('Librarian') && @user
@reserve.assign_attributes(
user: @user,
pickup_location: @user.profile.library
)
else
if @user.present?
if @user != current_user
access_denied
return
end
end
@reserve.user_number = current_user.profile.user_number
@reserve.assign_attributes(
user_number: current_user.profile.user_number,
pickup_location: current_user.profile.library
)
end

@manifestation = Manifestation.find_by(id: params[:manifestation_id])
Expand Down
20 changes: 10 additions & 10 deletions app/views/reserves/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<%- if @sort_by == :created_at -%>
<strong><%= t('activerecord.attributes.reserve.created_at') -%></strong>
<%- else -%>
<%= link_to t('activerecord.attributes.reserve.created_at'), url_for(filtered_params.merge(sort_by: nil, only_path: true)) -%>
<%= link_to t('activerecord.attributes.reserve.created_at'), url_for(request.params.merge(sort_by: nil, only_path: true)) -%>
<% end %>
<%- if @sort_by == :title -%>
<strong><%= t('page.title') -%></strong>
<%- else -%>
<%= link_to t('page.title'), url_for(filtered_params.merge(sort_by: 'title', only_path: true)) -%>
<%= link_to t('page.title'), url_for(request.params.merge(sort_by: 'title', only_path: true)) -%>
<%- end -%>
</p>

Expand Down Expand Up @@ -103,15 +103,15 @@

<p>
<%- if @user -%>
<%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), url_for(filtered_params.merge(user_id: @user.username, format: :rss)) -%>
(<%= link_to 'RSS', url_for(filtered_params.merge(user_id: @user.username, format: :rss)) -%>)
<%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), url_for(filtered_params.merge(user_id: @user.username, format: :txt, locale: @locale.to_s)) -%>
(<%= link_to 'TSV', url_for(filtered_params.merge(user_id: @user.username, format: :txt, locale: @locale.to_s)) -%>)
<%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), url_for(request.params.merge(user_id: @user.username, format: :rss)) -%>
(<%= link_to 'RSS', url_for(request.params.merge(user_id: @user.username, format: :rss)) -%>)
<%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), url_for(request.params.merge(user_id: @user.username, format: :txt, locale: @locale.to_s)) -%>
(<%= link_to 'TSV', url_for(request.params.merge(user_id: @user.username, format: :txt, locale: @locale.to_s)) -%>)
<%- else -%>
<%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), url_for(filtered_params.merge(format: :rss)) -%>
(<%= link_to 'RSS', url_for(filtered_params.merge(format: :rss)) -%>)
<%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), url_for(filtered_params.merge(format: :txt, locale: @locale.to_s)) -%>
(<%= link_to 'TSV', url_for(filtered_params.merge(format: :txt, locale: @locale.to_s)) -%>)
<%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), url_for(request.params.merge(format: :rss)) -%>
(<%= link_to 'RSS', url_for(request.params.merge(format: :rss)) -%>)
<%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), url_for(request.params.merge(format: :txt, locale: @locale.to_s)) -%>
(<%= link_to 'TSV', url_for(request.params.merge(format: :txt, locale: @locale.to_s)) -%>)
<%- end -%>
</p>
</div>
2 changes: 1 addition & 1 deletion spec/fixtures/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ profile_user2:
id: 5
user_id: 5
note:
library_id: 1
library_id: 3
created_at: 2008-01-18 13:29:06.922728 +09:00
required_role_id: 2
# user_number: '00005'
Expand Down
10 changes: 9 additions & 1 deletion spec/system/reserves_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
fixtures :all

describe 'When logged in as Librarian' do
it 'should contain user information' do
before(:each) do
sign_in users(:librarian1)
end

it 'should contain user information' do
visit reserves_path(format: :text)
expect(page).to have_content reserves(:reserve_00001).user.username
expect(page).to have_content reserves(:reserve_00001).manifestation.original_title
end

it 'should set default library' do
visit new_reserve_path(user_id: users(:user2))
expect(page).to have_select('reserve[pickup_location_id]', selected: 'Hachioji Library')
end
end
end
29 changes: 29 additions & 0 deletions spec/views/reserves/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rails_helper'

describe "reserves/index" do
fixtures :users, :roles, :user_has_roles, :reserves

before(:each) do
view.extend EnjuLeaf::ApplicationHelper

assign(:reserves, Reserve.page(1))
view.stub(:current_user).and_return(User.find_by(username: 'enjuadmin'))
end

it "renders a list of reserves" do
allow(view).to receive(:policy).and_return double(create?: true, update?: true, destroy?: true)
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "tr>td:nth-child(1)", text: reserves(:reserve_00001).id.to_s
assert_select "tr>td:nth-child(2)", text: /#{reserves(:reserve_00001).user.username}/
assert_select "tr>td:nth-child(2)", text: /#{reserves(:reserve_00002).manifestation.original_title}/
end

it "renders a list of reserves when a reserve does not have expired_at" do
reserve = FactoryBot.create(:reserve, expired_at: nil)
assign(:reserves, Reserve.page(2))
allow(view).to receive(:policy).and_return double(create?: true, update?: true, destroy?: true)
render
rendered.should match /<td/
end
end