Skip to content

Commit 0bece08

Browse files
committed
Remove problematic admin create session endpoint
1 parent d2a9bfc commit 0bece08

File tree

4 files changed

+1
-74
lines changed

4 files changed

+1
-74
lines changed

app/controllers/admin/legacy/sessions_controller.rb

-27
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ def edit
1111
respond_with(@session)
1212
end
1313

14-
def new
15-
respond_with(@session)
16-
end
17-
1814
def update
1915
if @session.update(session_params)
2016
redirect_to admin_legacy_sessions_path
@@ -23,29 +19,6 @@ def update
2319
end
2420
end
2521

26-
def build_presenter
27-
name = params[:session].delete(:name)
28-
# find exact match by name
29-
Participant.where(name: name).first_or_initialize do |p|
30-
p.save(validate: false) if p.new_record?
31-
end
32-
end
33-
34-
def create
35-
@session.participant = build_presenter
36-
@session.attributes = session_params
37-
@session.event = Event.current_event
38-
@session.timeslot_id = params[:session][:timeslot_id]
39-
@session.room_id = params[:session][:room_id]
40-
41-
if @session.save
42-
flash[:notice] = "Presentation added"
43-
redirect_to admin_legacy_sessions_path
44-
else
45-
render :new
46-
end
47-
end
48-
4922
def destroy
5023
@session.destroy!
5124
flash[:notice] = "Session has been deleted"

app/views/admin/legacy/sessions/index.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<% title('Admin: All sessions') %>
22

3-
<h2><%= link_to 'Add a session', new_admin_legacy_session_path %></h2>
4-
53
<div class="row">
64
<div class="column grid_6" style="margin-left:0px">
75
<ul class="sessionsList">

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
get '/legacy', to: 'legacy/admin#show', as: :legacy
4646
namespace :legacy do
4747
resource :config, only: [:show, :create]
48-
resources :sessions
48+
resources :sessions, except: [:new, :create]
4949
resources :markdown_contents, path: 'markdown-contents'
5050
resources :events do
5151
resources :timeslots, only: [:index, :new, :create]

spec/controllers/admin/legacy/sessions_controller_spec.rb

-44
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,4 @@
4343
end
4444
end
4545
end
46-
47-
describe "create" do
48-
let!(:event) { create(:event) }
49-
let(:category) { Category.last }
50-
before do
51-
Participant.destroy_all
52-
create(:participant, name: "Joe Schmoe")
53-
end
54-
55-
context "with valid values" do
56-
it "creates a new session " do
57-
58-
expect {
59-
expect {
60-
post :create, params: { session: { title: 'new title', description: 'new description', category_ids: [category.id], level_id: '2', name: "Ada Lovelace"} }
61-
}.to change { Session.count }.by(1)
62-
}.to change { Participant.count }.by(1)
63-
expect(response).to redirect_to admin_legacy_sessions_path
64-
expect(assigns[:session].title).to eq 'new title'
65-
expect(assigns[:session].participant.name).to eq 'Ada Lovelace'
66-
expect(assigns[:session].event).to eq event
67-
expect(assigns[:session].category_ids).to include category.id
68-
expect(flash[:notice]).to eq "Presentation added"
69-
end
70-
end
71-
72-
context "with invalid values" do
73-
it "shows the errors" do
74-
75-
expect {
76-
post :create, params: { session: { title: ''} }
77-
}.not_to change { Session.count }
78-
expect(response).to render_template('new')
79-
end
80-
end
81-
end
82-
83-
describe "new" do
84-
it "should be successful" do
85-
get :new
86-
expect(response).to be_successful
87-
expect(assigns[:session]).to be_kind_of Session
88-
end
89-
end
9046
end

0 commit comments

Comments
 (0)