Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserFlowTest < ActionDispatch::IntegrationTest
- def login
- post ns_login_user_path, { :user => { :username => 'user', :password => 'password' } }
- assert_response 200
- end
- test "should complete a flow" do
- login
- post create_participant_path(:event_id => events(:retoe).id), {
- :format => :json,
- :event_role => event_roles(:regular_participant).id,
- :in_team => true
- }
- r = JSON.parse(response.body)
- assert_response 200
- puts "response creating participation #{r.as_json}"
- participant_id = r[:participant_id]
- end
- end
- # Events
- scope 'events', :controller => :events do
- # some routes
- scope ':event_id', :controller => :events do
- # some routes
- scope 'participants', :controller => :participants do
- post '', :action => :create_participant, :as => :create_participant
- # some routes
- end
- end
- end
- class ParticipantsController < ApiController
- before_action :require_login, :only => [:create_participant, :update_participant]
- # Creates a participation of a person in the event
- # Receives the following params:
- # - +event_id+
- # - +in_team+::_boolean
- # - +event_role+
- def create_participant
- # … some logic
- if participant.save
- render :status => :ok, :json => Hash[
- :participant_id => participant.id,
- :team_participant_id => participant.team_participant_id
- ]
- else
- render :status => 406, :json => Hash[
- :message => t('alerts.error_saving'),
- :errors => participant.errors.as_json
- ]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement