Merge 48287a24d7 into 02d75ec729
This commit is contained in:
commit
da51dc3a72
6 changed files with 21 additions and 27 deletions
|
|
@ -3,6 +3,7 @@ module Admin
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :venue, through: :conference, singleton: true
|
load_and_authorize_resource :venue, through: :conference, singleton: true
|
||||||
load_and_authorize_resource through: :venue
|
load_and_authorize_resource through: :venue
|
||||||
|
after_action :prepare_unobtrusive_flash, only: [:create]
|
||||||
|
|
||||||
def index; end
|
def index; end
|
||||||
|
|
||||||
|
|
@ -14,12 +15,13 @@ module Admin
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@room = @venue.rooms.new(room_params)
|
@room = @venue.rooms.new(room_params)
|
||||||
if @room.save
|
respond_to do |format|
|
||||||
redirect_to admin_conference_venue_rooms_path(conference_id: @conference.short_title),
|
if @room.save
|
||||||
notice: 'Room successfully created.'
|
flash.now[:notice] = 'Room successfully created.'
|
||||||
else
|
else
|
||||||
flash.now[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}."
|
flash.now[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}."
|
||||||
render :new
|
end
|
||||||
|
format.js
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
= @room.name
|
= @room.name
|
||||||
.row
|
.row
|
||||||
.col-md-8
|
.col-md-8
|
||||||
= semantic_form_for(@room, url: (@room.new_record? ? admin_conference_venue_rooms_path : admin_conference_venue_room_path(@conference.short_title, @room))) do |f|
|
= semantic_form_for(@room, url: (@room.new_record? ? admin_conference_venue_rooms_path : admin_conference_venue_room_path(@conference.short_title, @room)), remote: (true if @room.new_record?)) do |f|
|
||||||
= f.input :name, input_html: { autofocus: true}
|
= f.input :name, input_html: { autofocus: true}, id: 'room_name'
|
||||||
= f.input :size, input_html: {size: 5}
|
= f.input :size, input_html: {size: 5}, id: 'room_size'
|
||||||
%p.text-right
|
%p.text-right
|
||||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||||
|
|
|
||||||
2
app/views/admin/rooms/create.js.erb
Normal file
2
app/views/admin/rooms/create.js.erb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
$('#room_name').val('');
|
||||||
|
$('#room_size').val('');
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
-# Index admin sidebar
|
-# Index admin sidebar
|
||||||
= render 'layouts/admin_sidebar_index'
|
= render 'layouts/admin_sidebar_index'
|
||||||
.col-md-10
|
.col-md-10
|
||||||
#messages
|
#messages.unobtrusive-flash-container
|
||||||
=render 'layouts/messages'
|
=render 'layouts/messages'
|
||||||
#content
|
#content
|
||||||
= yield
|
= yield
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,9 @@ describe Admin::RoomsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context 'saves successfuly' do
|
context 'saves successfuly', js: true do
|
||||||
before do
|
before do
|
||||||
post :create, room: attributes_for(:room), conference_id: conference.short_title
|
xhr :post, :create, room: attributes_for(:room), conference_id: conference.short_title
|
||||||
end
|
|
||||||
|
|
||||||
it 'redirects to admin room index path' do
|
|
||||||
expect(response).to redirect_to admin_conference_venue_rooms_path(conference_id: conference.short_title)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows success message in flash notice' do
|
it 'shows success message in flash notice' do
|
||||||
|
|
@ -69,11 +65,7 @@ describe Admin::RoomsController do
|
||||||
context 'save fails' do
|
context 'save fails' do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(Room).to receive(:save).and_return(false)
|
allow_any_instance_of(Room).to receive(:save).and_return(false)
|
||||||
post :create, room: attributes_for(:room), conference_id: conference.short_title
|
xhr :post, :create, room: attributes_for(:room), conference_id: conference.short_title
|
||||||
end
|
|
||||||
|
|
||||||
it 'renders new template' do
|
|
||||||
expect(response).to render_template('new')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows error in flash message' do
|
it 'shows error in flash message' do
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,9 @@ feature Room do
|
||||||
click_button 'Create Room'
|
click_button 'Create Room'
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
expect(flash).to eq('Room successfully created.')
|
expect(page).to have_css '#messages', text: 'Room successfully created.'
|
||||||
within('table#rooms') do
|
expect(page).to have_css '#room_size', text: ''
|
||||||
expect(page.has_content?('Auditorium')).to be true
|
expect(page).to have_css '#room_name', text: ''
|
||||||
expect(page.assert_selector('tr', count: 2)).to be true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'updates a room', feature: true, js: true do
|
scenario 'updates a room', feature: true, js: true do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue