* VRFS-15 cleaning up location of files and superflous use of 'api' in file names.
This commit is contained in:
parent
eb9f0d791c
commit
6f14c505c3
|
|
@ -0,0 +1,54 @@
|
|||
class ApiMusicSessionsController < ApplicationController
|
||||
|
||||
# have to be signed in currently to see this screen
|
||||
before_filter :signed_in_user
|
||||
|
||||
respond_to :json
|
||||
|
||||
def index
|
||||
@music_sessions = MusicSession.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def create
|
||||
@music_session = MusicSession.new()
|
||||
@music_session.creator = current_user
|
||||
@music_session.description = params[:description]
|
||||
@music_session.save
|
||||
respond_with @music_session, responder: ApiResponder, :location => api_session_detail_url(@music_session)
|
||||
end
|
||||
|
||||
def show
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
end
|
||||
|
||||
def delete
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
@music_session.delete
|
||||
|
||||
respond_with @music_session, responder: ApiResponder
|
||||
end
|
||||
|
||||
def client_show
|
||||
@music_session_client = MusicSessionClient.find(params[:id])
|
||||
end
|
||||
|
||||
def client_create
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
@music_session_client = MusicSessionClient.new()
|
||||
@music_session_client.ip_address = params[:ip_address]
|
||||
@music_session_client.music_session = @music_session
|
||||
@music_session_client.user = current_user
|
||||
@music_session_client.save
|
||||
|
||||
respond_with @music_session_client, responder: ApiResponder, :location => api_session_client_detail_url(@music_session_client)
|
||||
end
|
||||
|
||||
def client_delete
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
@music_session_client = MusicSessionClient.find_by_user_id_and_music_session_id(current_user, @music_session)
|
||||
@music_session_client.delete
|
||||
|
||||
respond_with @music_session_client, responder: ApiResponder
|
||||
end
|
||||
end
|
||||
|
|
@ -3,36 +3,14 @@ class MusicSessionsController < ApplicationController
|
|||
# have to be signed in currently to see this screen
|
||||
before_filter :signed_in_user
|
||||
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
|
||||
def api_index
|
||||
@music_sessions = MusicSession.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def api_create
|
||||
@music_session = MusicSession.new()
|
||||
@music_session.creator = current_user
|
||||
@music_session.description = params[:description]
|
||||
@music_session.save
|
||||
respond_with @music_session, responder: ApiResponder, :location => api_session_detail_url(@music_session)
|
||||
end
|
||||
|
||||
def api_show
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
end
|
||||
|
||||
def api_member_create
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
MusicSessionClient.ip_address = params[:ip_address]
|
||||
end
|
||||
respond_to :html
|
||||
|
||||
def index
|
||||
@music_sessions = MusicSession.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
# use gon to pass variables into javascript
|
||||
gon.websocket_gateway_uri = Rails.application.config.websocket_gateway_uri
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
object @music_sessions
|
||||
|
||||
extends "api_music_sessions/show"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
object @music_session_client
|
||||
|
||||
attributes :id, :ip_address
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<li>
|
||||
<%= link_to music_session.name, music_session %>
|
||||
<%= link_to music_session.description, music_session %>
|
||||
<% if music_session.creator == current_user || current_user.admin %>
|
||||
| <%= link_to "delete", music_session, method: :delete,
|
||||
data: { confirm: "You sure?" } %>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
object @music_sessions
|
||||
|
||||
extends "music_sessions/api_show"
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<% provide(:title, 'Jam Sessions') %>
|
||||
<h1>Jam Sessions</h1>
|
||||
<% provide(:title, 'Music Sessions') %>
|
||||
<h1>Music Sessions</h1>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,13 @@ SampleApp::Application.routes.draw do
|
|||
match '/client', to: 'clients#index'
|
||||
|
||||
scope '/api' do
|
||||
match '/sessions/:id' => 'music_sessions#api_show', :via => :get, :as => 'api_session_detail'
|
||||
match '/sessions' => 'music_sessions#api_index', :via => :get
|
||||
match '/sessions' => 'music_sessions#api_create', :via => :post
|
||||
match '/sessions/:id/musician' => 'api_music_sessions#client_show', :via => :get, :as => 'api_session_client_detail'
|
||||
match '/sessions/:id/musician' => 'api_music_sessions#client_create', :via => :post
|
||||
match '/sessions/:id/musician' => 'api_music_sessions#client_delete', :via => :delete
|
||||
match '/sessions/:id' => 'api_music_sessions#show', :via => :get, :as => 'api_session_detail'
|
||||
match '/sessions/:id' => 'api_music_sessions#delete', :via => :delete
|
||||
match '/sessions' => 'api_music_sessions#index', :via => :get
|
||||
match '/sessions' => 'api_music_sessions#create', :via => :post
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ describe "Authentication" do
|
|||
click_button "Sign in"
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: user.name) }
|
||||
# it now goes to /music_sessions
|
||||
it { should have_selector('title', text: "Music Sessions") }
|
||||
|
||||
it { should have_link('Users', href: users_path) }
|
||||
it { should have_link('Profile', href: user_path(user)) }
|
||||
|
|
@ -78,7 +79,8 @@ describe "Authentication" do
|
|||
end
|
||||
|
||||
it "should render the default (profile) page" do
|
||||
page.should have_selector('title', text: user.name)
|
||||
# it now goes to /music_sessions
|
||||
page.should have_selector('title', text: "Music Sessions")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ describe "Music Session API ", :type => :api do
|
|||
|
||||
subject { page }
|
||||
|
||||
|
||||
describe "profile page" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do 2
|
||||
before do
|
||||
#sign_in user
|
||||
MusicSession.delete_all
|
||||
|
||||
post '/sessions', "session[email]" => user.email, "session[password]" => user.password
|
||||
rack_mock_session.cookie_jar["remember_token"].should == user.remember_token
|
||||
end
|
||||
|
|
@ -34,5 +35,72 @@ describe "Music Session API ", :type => :api do
|
|||
|
||||
list[0]["id"].should == music_session["id"]
|
||||
end
|
||||
|
||||
|
||||
it "should delete session" do
|
||||
# check that there are no sessions
|
||||
get '/api/sessions.json'
|
||||
list = JSON.parse(last_response.body)
|
||||
list.length.should == 0
|
||||
|
||||
# create the session
|
||||
post '/api/sessions.json', '{"description" : "a session"}', "CONTENT_TYPE" => 'application/json'
|
||||
|
||||
# now fetch it's data
|
||||
get last_response.headers["Location"]
|
||||
music_session = JSON.parse(last_response.body)
|
||||
|
||||
get '/api/sessions.json'
|
||||
list = JSON.parse(last_response.body)
|
||||
list.length.should == 1
|
||||
|
||||
delete "/api/sessions/#{music_session["id"]}.json", '', "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(204)
|
||||
|
||||
get '/api/sessions.json'
|
||||
list = JSON.parse(last_response.body)
|
||||
list.length.should == 0
|
||||
end
|
||||
|
||||
|
||||
it "should add/remove member from session" do
|
||||
# create the session
|
||||
post '/api/sessions.json', '{"description" : "a session"}', "CONTENT_TYPE" => 'application/json'
|
||||
|
||||
# now fetch it's data
|
||||
get last_response.headers["Location"]
|
||||
music_session = JSON.parse(last_response.body)
|
||||
music_session["musicians"].length.should == 0
|
||||
|
||||
# create a member
|
||||
post "/api/sessions/#{music_session["id"]}/musician.json", '{ "ip_address" : "1.2.3.4" }', "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
|
||||
musician = JSON.parse(last_response.body)
|
||||
|
||||
# re-fetch the session now that there is a musician
|
||||
get "/api/sessions/#{music_session["id"]}.json"
|
||||
music_session = JSON.parse(last_response.body)
|
||||
|
||||
# there should be one musician in the response
|
||||
music_session["musicians"].length.should == 1
|
||||
musician = music_session["musicians"][0]
|
||||
|
||||
# and that musician should have the same IP address
|
||||
musician["ip_address"].should == "1.2.3.4"
|
||||
|
||||
# now delete that musician
|
||||
delete "/api/sessions/#{music_session["id"]}/musician.json", '', "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(204)
|
||||
|
||||
# re-fetch the session now that there is not a musician
|
||||
get "/api/sessions/#{music_session["id"]}.json"
|
||||
music_session = JSON.parse(last_response.body)
|
||||
|
||||
# there should be no musicians in the response
|
||||
music_session["musicians"].length.should == 0
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue