Skip to content

Commit

Permalink
Set controller up to distinguish valid params
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Sep 12, 2016
1 parent 9a350d2 commit 052a61c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/controllers/shelf_selection_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ def new

def create
@shelf_selection_report = ShelfSelectionReport.new(params[:shelf_selection_report])
flash[:notice] = 'Shelf Selection Report params submitted!'
redirect_to root_url
if @shelf_selection_report.valid?
flash[:notice] = 'Shelf Selection Report params submitted!'
# save to shelf_sel_search
redirect_to root_url
else
render action: 'new'
end
end

def home_locations
Expand Down
1 change: 1 addition & 0 deletions app/models/shelf_selection_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ShelfSelectionReport
:mhlds, :has_dups, :multvol, :multcop, :no_boundw,
:range_type, :call_alpha, :subj_name,
:save_opt, :search_name, :call_lo, :call_hi
validates :email, presence: true

def self.generic_options
[["Doesn't matter", 0], ['INCLUDE only', 1], ['EXCLUDE', 2]]
Expand Down
9 changes: 7 additions & 2 deletions spec/controllers/shelf_selection_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
end

describe 'post#create' do
it 'redirects to root_url' do
it 'redirects to root_url when params are valid' do
stub_current_user(FactoryGirl.create(:authorized_user))
post :create, shelf_selection_report: { email: '' }
post :create, shelf_selection_report: { email: 'testuser@test.org' }
expect(response).to redirect_to root_url
end
it 'renders the new action when params are invalid' do
stub_current_user(FactoryGirl.create(:authorized_user))
post :create, shelf_selection_report: { email: '' }
expect(response).to render_template('new')
end
end
end

0 comments on commit 052a61c

Please sign in to comment.