Skip to content

Commit

Permalink
Merge pull request #98 from nikhilgupta1211/createevntorg
Browse files Browse the repository at this point in the history
Added validation for user_id and event_id in event_organizer
  • Loading branch information
bgeuken committed Aug 17, 2017
2 parents c8df925 + 21c8879 commit bad8a51
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/event_organizer.rb
Expand Up @@ -4,7 +4,8 @@ class EventOrganizer < ActiveRecord::Base

attr_accessor(:user_email)

validates :user_email, presence: true
validates :user_email, :event_id, presence: true
validates :user_id, presence: { message: 'No such user exist' }
validates :user_id, uniqueness: { scope: :event_id, message: 'Already an event organizer for this event' }

def self.autocomplete_users(term)
Expand Down
10 changes: 10 additions & 0 deletions spec/features/event_organizers_spec.rb
Expand Up @@ -31,4 +31,14 @@
click_button 'Add'
page.should have_content 'Event Organizer Added'
end

scenario 'When entered user does not exist', js: true do
sign_in_as_user(users(:tspmember))
visit new_event_event_organizer_path(events(:party))

fill_in 'event_organizer_user_email', with: 'random_user'
click_button 'Add'

page.should have_content 'No such user exist'
end
end
2 changes: 2 additions & 0 deletions spec/models/event_organizer_spec.rb
Expand Up @@ -7,6 +7,8 @@
it { should belong_to(:event) }

it { should validate_presence_of :user_email }
it { should validate_presence_of(:user_id).with_message('No such user exist') }
it { should validate_presence_of :event_id }
it { should validate_uniqueness_of(:user_id).scoped_to(:event_id).with_message('Already an event organizer for this event') }

it 'nickname and email of the user' do
Expand Down

0 comments on commit bad8a51

Please sign in to comment.