Skip to content

Commit

Permalink
Actually respect allow_event_email flag when sending event announcements
Browse files Browse the repository at this point in the history
Fixup some tests to run better in postgres
  • Loading branch information
tjgrathwell committed Apr 10, 2014
1 parent a9230ae commit 4647252
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def diets
end

def unpublished
@chapter_user_counts = Hash[Chapter.includes(:users).map { |chapter|
@chapter_user_counts = Hash[Chapter.includes(:users).where('users.allow_event_email = ?', true).map { |chapter|
[chapter.id, chapter.users.length]
}]
@events = Event.where(published: false)
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/event_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def new_event(event)
@chapter = @event.chapter

headers['X-SMTPAPI'] = {
to: User.joins(:chapters).where('chapters.id' => [@chapter.id]).map(&:email)
to: User.joins(:chapters).where('users.allow_event_email = ?', true).where('chapters.id' => [@chapter.id]).map(&:email)
}.to_json

mail(
Expand Down
2 changes: 1 addition & 1 deletion app/services/meetup_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def disassociate_user bridgetroll_user
def find_user(meetup_id)
meetup_user = MeetupUser.where(meetup_id: meetup_id).first_or_initialize

associated_user = User.joins(:authentications).where('authentications.provider = ? AND authentications.uid = ?', 'meetup', meetup_id).first
associated_user = User.joins(:authentications).where('authentications.provider = ? AND authentications.uid = ?', 'meetup', meetup_id.to_s).first
if associated_user.present?
associated_user
else
Expand Down
37 changes: 37 additions & 0 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,40 @@ def make_request
end
end

describe "GET unpublished" do
before do
@chapter1 = @event.chapter
@chapter1.update_attributes(name: 'RailsBridge Shellmound')
@chapter2 = create(:chapter, name: 'RailsBridge Meriloft')

user_none = create(:user)

user_chapter1 = create(:user)
user_chapter1.chapters << @chapter1

user_chapter2 = create(:user)
user_chapter2.chapters << @chapter2

user_both_chapters = create(:user)
user_both_chapters.chapters << @chapter1
user_both_chapters.chapters << @chapter2

user_no_email = create(:user, allow_event_email: false)
user_no_email.chapters << @chapter1

sign_in create(:user, publisher: true)
end

it "assigns a hash of chapter/user counts" do
get :unpublished

assigns(:chapter_user_counts).should == {
@chapter1.id => 2,
@chapter2.id => 2
}
end
end

describe "POST publish" do
before do
this_chapter = @event.chapter
Expand All @@ -516,6 +550,9 @@ def make_request
@user_this_chapter = create(:user)
@user_this_chapter.chapters << this_chapter

@user_no_email = create(:user, allow_event_email: false)
@user_no_email.chapters << this_chapter

@user_other_chapter = create(:user)
@user_other_chapter.chapters << other_chapter

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@event2 = create(:event)

@event1.rsvps << create(:rsvp, user: @user_associated, event: @event1)
@bridgetroll_user.authentications.create(provider: 'meetup', uid: @user_associated.meetup_id)
@bridgetroll_user.authentications.create(provider: 'meetup', uid: @user_associated.meetup_id.to_s)

@event1.rsvps << create(:rsvp, user: @user1, event: @event1)
@event2.rsvps << create(:rsvp, user: @user1, event: @event2)
Expand Down
6 changes: 3 additions & 3 deletions spec/services/meetup_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
describe "when users have already associated their meetup id with Bridgetroll" do
let(:bridgetroll_user) { create(:user) }
before do
bridgetroll_user.authentications.create(provider: 'meetup', uid: sally[:id])
bridgetroll_user.authentications.create(provider: 'meetup', uid: sally[:id].to_s)

@importer.import_student_and_volunteer_event(event_params)
end
Expand Down Expand Up @@ -214,14 +214,14 @@
it "claims existing RSVPs when associating" do
@event.volunteers_with_legacy.should =~ [@sven_model, @sally_model]

bridgetroll_user.authentications.create(provider: 'meetup', uid: sven[:id])
bridgetroll_user.authentications.create(provider: 'meetup', uid: sven[:id].to_s)

@event.reload.volunteers_with_legacy.should =~ [bridgetroll_user, @sally_model]
end

context "when a bridgetroll user is already associated to a meetup user" do
before do
bridgetroll_user.authentications.create(provider: 'meetup', uid: sven[:id])
bridgetroll_user.authentications.create(provider: 'meetup', uid: sven[:id].to_s)
end

it "removes claim to RSVPs when disassociating" do
Expand Down

0 comments on commit 4647252

Please sign in to comment.