Advertisement
Guest User

Untitled

a guest
May 31st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. class UserFlowTest < ActionDispatch::IntegrationTest
  2. def login
  3. post ns_login_user_path, { :user => { :username => 'user', :password => 'password' } }
  4. assert_response 200
  5. end
  6.  
  7. test "should complete a flow" do
  8. login
  9. post create_participant_path(:event_id => events(:retoe).id), {
  10. :format => :json,
  11. :event_role => event_roles(:regular_participant).id,
  12. :in_team => true
  13. }
  14. r = JSON.parse(response.body)
  15. assert_response 200
  16. puts "response creating participation #{r.as_json}"
  17. participant_id = r[:participant_id]
  18. end
  19. end
  20.  
  21. # Events
  22. scope 'events', :controller => :events do
  23. # some routes
  24. scope ':event_id', :controller => :events do
  25. # some routes
  26. scope 'participants', :controller => :participants do
  27. post '', :action => :create_participant, :as => :create_participant
  28. # some routes
  29. end
  30. end
  31. end
  32.  
  33. class ParticipantsController < ApiController
  34.  
  35. before_action :require_login, :only => [:create_participant, :update_participant]
  36.  
  37. # Creates a participation of a person in the event
  38. # Receives the following params:
  39. # - +event_id+
  40. # - +in_team+::_boolean
  41. # - +event_role+
  42. def create_participant
  43. # … some logic
  44. if participant.save
  45. render :status => :ok, :json => Hash[
  46. :participant_id => participant.id,
  47. :team_participant_id => participant.team_participant_id
  48. ]
  49. else
  50. render :status => 406, :json => Hash[
  51. :message => t('alerts.error_saving'),
  52. :errors => participant.errors.as_json
  53. ]
  54. end
  55. end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement