Skip to content

Commit

Permalink
Merge branch 'hotfix/0.3.8_fix.5'
Browse files Browse the repository at this point in the history
* hotfix/0.3.8_fix.5:
  Fix event in admin panel
  • Loading branch information
kalashnikovisme committed Jul 28, 2015
2 parents e273139 + 27ebc6c commit 66033a8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/controllers/web/admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class Web::Admin::ApplicationController < Web::ApplicationController

protected

def choose_users
@users = User.presented.decorate
end

def choose_members
@members = Member.presented.decorate
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/web/admin/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Web::Admin::EventsController < Web::Admin::ApplicationController
before_filter :choose_teams, only: [ :new, :edit ]
before_filter :choose_users, only: [ :new, :edit ]
before_filter :choose_members, only: [ :new, :edit ]

def index
Expand All @@ -26,6 +27,7 @@ def create
redirect_to admin_events_path
else
choose_teams
choose_users
choose_members
render action: :new
end
Expand All @@ -38,6 +40,7 @@ def update
redirect_to edit_admin_event_path @event_form.model
else
choose_teams
choose_users
choose_members
render action: :edit
end
Expand Down
4 changes: 4 additions & 0 deletions app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def profile_avatar
end

alias element_avatar profile_avatar

def select_presentation
"#{ticket}#{ticket ? ' | ' : ''} #{first_name} #{last_name}"
end
end
7 changes: 7 additions & 0 deletions app/helpers/web/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
module Web::UsersHelper
def users_hash(users)
users_hash = {}
users.each do |user|
users_hash[user.select_presentation] = user.id
end
users_hash
end
end
4 changes: 3 additions & 1 deletion app/models/event/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class Event::Registration < ActiveRecord::Base
belongs_to :event
belongs_to :user

validates :user_id, uniqueness: { scope: [ :event_id ] }
validates :user_id, presence: true,
uniqueness: { scope: [ :event_id ] }
validates :event_id, presence: true

include Event::RegistrationScopes
extend Enumerize
Expand Down
2 changes: 1 addition & 1 deletion app/views/web/admin/events/_registration_fields.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.registration_fields
= f.input :user_id, as: :select, collection: members_hash(@members), input_html: { class: :select2 }
= f.input :user_id, as: :select, collection: users_hash(@users), input_html: { class: :select2 }
= f.input :role, as: :select, collection: enumerize_locales_hash(Event::Registration, :role)
= link_to_remove_association 'X', f, class: 'btn btn-danger remove-registration', data: { 'wrapper-class' => 'registration_fields' }
6 changes: 5 additions & 1 deletion test/controllers/web/admin/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Web::Admin::EventsControllerTest < ActionController::TestCase
sign_in admin
create :member
@event = create :event
stub_request(:get, "https://api.foursquare.com/v2/venues/#{@event.place}?client_id=#{OAUTH_KEYS[:foursquare][:client_id]}&client_secret=#{OAUTH_KEYS[:foursquare][:client_secret]}&v=#{configus.api.foursquare.version}").with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby gem'}).to_return(status: 200, body: File.new("#{Rails.root}/test/mock/foursquare/place.json"), headers: {})
end

test 'should get index' do
Expand All @@ -20,14 +21,17 @@ class Web::Admin::EventsControllerTest < ActionController::TestCase

test 'should create event' do
attributes = attributes_for :event
# FIXME put in factory
attributes[:registrations_attributes] = {
'0' => attributes_for(:event_registration)
}
post :create, event: attributes
assert_response :redirect
assert_redirected_to admin_events_path
assert_equal attributes[:title], Event.last.title
end

test 'should get edit' do
stub_request(:get, "https://api.foursquare.com/v2/venues/#{@event.place}?client_id=#{OAUTH_KEYS[:foursquare][:client_id]}&client_secret=#{OAUTH_KEYS[:foursquare][:client_secret]}&v=#{configus.api.foursquare.version}").with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby gem'}).to_return(status: 200, body: File.new("#{Rails.root}/test/mock/foursquare/place.json"), headers: {})
get :edit, id: @event
assert_response :success, @response.body
end
Expand Down
1 change: 1 addition & 0 deletions test/controllers/web/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Web::EventsControllerTest < ActionController::TestCase
@member = create :member
@event = create :event, creator: @member
sign_in @member
stub_request(:get, "https://api.foursquare.com/v2/venues/#{@event.place}?client_id=#{OAUTH_KEYS[:foursquare][:client_id]}&client_secret=#{OAUTH_KEYS[:foursquare][:client_secret]}&v=#{configus.api.foursquare.version}").with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby gem'}).to_return(status: 200, body: File.new("#{Rails.root}/test/mock/foursquare/place.json"), headers: {})
end

test 'should get index' do
Expand Down

0 comments on commit 66033a8

Please sign in to comment.