Skip to content

Commit

Permalink
Merge pull request #90 from nikhilgupta1211/users_event_method
Browse files Browse the repository at this point in the history
Users for an event method
  • Loading branch information
bgeuken committed Aug 4, 2017
2 parents b54f769 + 0079272 commit 0fb0e4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def event_title_line(event)
end

def users_for_event(state)
req = @event.requests
req = req.where(state: state) if state != 'all'
user_email = req.map { |e| e.user.email }.uniq
requests = @event.travel_sponsorships.includes(:user).accessible_by(current_ability)
requests = requests.where(state: state) if state != 'all'
requests.distinct.pluck('users.email')
end
end
6 changes: 3 additions & 3 deletions spec/features/event_emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
page.check('Submitted')
page.check('Incomplete')
page.should have_field('To', with: 'gial.ackbar@rebel-alliance.org,luke.skywalker@rebel-alliance.org,evram.lajaie@rebel-alliance.org,'\
'john.skywalker@rebel-alliance.org,c3po@droids.com,wedge.antilles@rebel-alliance.org')
'c3po@droids.com,wedge.antilles@rebel-alliance.org')

page.check('All')
page.should have_field('To', with: 'gial.ackbar@rebel-alliance.org,luke.skywalker@rebel-alliance.org,evram.lajaie@rebel-alliance.org,'\
'john.skywalker@rebel-alliance.org,c3po@droids.com,wedge.antilles@rebel-alliance.org')
'c3po@droids.com,wedge.antilles@rebel-alliance.org')

fill_in 'Subject', with: "Death Star's destruction celebration"
fill_in 'event_email_body', with: "Event Death Star's destruction celebration to be conducted soon. Be ready."

page.find('.btn-primary').trigger('click')
page.should have_content 'Email Delivered'
ActionMailer::Base.deliveries.size.should == @deliveries + 6
ActionMailer::Base.deliveries.size.should == @deliveries + 5
end

scenario 'Sending mail without a body and a subject', js: true do
Expand Down
6 changes: 4 additions & 2 deletions spec/helpers/events_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
before :each do
@event = events(:party)
end
let(:user) { users(:tspmember) }
let(:current_ability) { Ability.new(user) }

describe '#users_for_event' do
it 'returns email of all the participants of the event' do
expect(users_for_event('all')).to eq(['gial.ackbar@rebel-alliance.org', 'luke.skywalker@rebel-alliance.org', 'wedge.antilles@rebel-alliance.org',
'evram.lajaie@rebel-alliance.org', 'john.skywalker@rebel-alliance.org', 'c3po@droids.com'])
'evram.lajaie@rebel-alliance.org', 'c3po@droids.com'])
end
it 'returns emails of participants with their request in submitted state' do
expect(users_for_event('submitted')).to eq(['wedge.antilles@rebel-alliance.org'])
end
it 'returns emails of participants with their request in incomplete state' do
expect(users_for_event('incomplete')).to eq(['gial.ackbar@rebel-alliance.org', 'luke.skywalker@rebel-alliance.org', 'evram.lajaie@rebel-alliance.org',
'john.skywalker@rebel-alliance.org', 'c3po@droids.com'])
'c3po@droids.com'])
end
it 'returns emails of participants with their request in canceled state' do
expect(users_for_event('canceled')) .to eq([])
Expand Down

0 comments on commit 0fb0e4b

Please sign in to comment.