PageRenderTime 71ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/features/step_definitions/invitation_to_join_group_steps.rb

https://bitbucket.org/denjell/loomio_gv
Ruby | 282 lines | 230 code | 52 blank | 0 comment | 6 complexity | af435981672dd83e5a7bc318ac190b42 MD5 | raw file
Possible License(s): AGPL-3.0
  1. Given(/^I am a group admin$/) do
  2. @group_admin = FactoryGirl.create(:user)
  3. @group = FactoryGirl.create(:group)
  4. @group.add_admin! @group_admin
  5. login_automatically @group_admin
  6. end
  7. When(/^I invite "(.*?)" to our group$/) do |arg1|
  8. visit group_path(@group)
  9. click_on 'Invite people'
  10. fill_in "invitees", with: arg1
  11. click_on 'Invite people'
  12. end
  13. When(/^I invite bill and jane to our group$/) do
  14. ActionMailer::Base.deliveries = []
  15. visit group_path(@group)
  16. click_on 'Invite people'
  17. fill_in "invitees", with: 'bill@example.org, jane@example.org'
  18. click_on 'Invite people'
  19. end
  20. Then(/^bill and jane should both have invitations to join$/) do
  21. emails = ActionMailer::Base.deliveries.map(&:to).flatten.sort
  22. emails.should == %w[bill@example.org jane@example.org]
  23. end
  24. Then(/^"(.*?)" should get an invitation to join the group$/) do |arg1|
  25. last_email = ActionMailer::Base.deliveries.last
  26. last_email.to.should == [arg1]
  27. last_email.reply_to.should == [@group_admin.email]
  28. end
  29. Given(/^there is a user called "(.*?)" with email "(.*?)"$/) do |arg1, arg2|
  30. @user = FactoryGirl.create(:user, name: arg1, email: arg2)
  31. end
  32. Then(/^"(.*?)" should be auto\-added to the group$/) do |arg1|
  33. @group.members.should include User.find_by_email('jim@jam.com')
  34. end
  35. Given(/^there is a group member with email "(.*?)"$/) do |arg1|
  36. @group_member = FactoryGirl.create(:user, email: arg1)
  37. @group.add_member! @group_member
  38. end
  39. Given(/^I am invited to join a group$/) do
  40. @group_admin = FactoryGirl.create(:user)
  41. @group = FactoryGirl.create(:group)
  42. @group.add_admin! @group_admin
  43. @invite_people_form = InvitePeopleForm.new(recipients: ['jim@jam.com'], message_body: 'please click the invitation link below')
  44. InvitationService.invite_to_group(recipient_emails: @invite_people_form.recipients, message: @invite_people_form.message_body, group: @group, inviter: @group_admin)
  45. end
  46. When(/^I accept my invitation via email$/) do
  47. invitation_url_regex = /https?:\/\/[\S]+/
  48. url = last_email_text_body.match(invitation_url_regex)[0]
  49. path = URI.parse(url).path
  50. visit path
  51. end
  52. When(/^I sign up as a new user$/) do
  53. fill_in :user_name, with: 'Jim Jameson'
  54. fill_in :user_email, with: 'jim@jam.com'
  55. fill_in :user_password, with: 'password'
  56. fill_in :user_password_confirmation, with: 'password'
  57. find('input[name=commit]').click()
  58. @user = User.find_by_email('jim@jam.com')
  59. end
  60. Then(/^I should see the signup form prepopulated with my email address$/) do
  61. page.should have_css('#user_email[value="jim@jam.com"]')
  62. end
  63. Given(/^I am invited at "(.*?)" to join a group$/) do |arg1|
  64. @group = FactoryGirl.create(:group)
  65. @invite_people_form = InvitePeopleForm.new(recipients: [arg1], message_body: 'please click the invitation link below')
  66. InvitationService.invite_to_group(recipient_emails: @invite_people_form.recipients, message: @invite_people_form.message_body, group: @group, inviter: @group.admins.first)
  67. end
  68. Then(/^I should be a member of the group$/) do
  69. @group.members.should include @user
  70. end
  71. When(/^I follow an invitation link I have already used$/) do
  72. @group = FactoryGirl.create(:group)
  73. @user = FactoryGirl.create(:user)
  74. @coordinator = FactoryGirl.create(:user)
  75. @group.add_admin!(@coordinator)
  76. @invitation = InvitationService.create_invite_to_join_group(group: @group,
  77. inviter: @coordinator,
  78. recipient_email: 'jim@jimmy.com')
  79. AcceptInvitation.and_grant_access!(@invitation, @user)
  80. visit invitation_path(@invitation)
  81. end
  82. Then(/^I should be redirected to the group page$/) do
  83. URI.parse(current_url).path.should include group_path(@group)
  84. end
  85. Then(/^I should be told the invitation link has already been used$/) do
  86. page.should have_content("This invitation has already been used. Please log in to continue to your group.")
  87. end
  88. When(/^I click an invitation link I have already used$/) do
  89. @group = FactoryGirl.create(:group)
  90. @coordinator = FactoryGirl.create(:user)
  91. @group.add_admin!(@coordinator)
  92. @invitation = InvitationService.create_invite_to_join_group(group: @group,
  93. inviter: @coordinator,
  94. recipient_email: 'jim@jimmy.com')
  95. AcceptInvitation.and_grant_access!(@invitation, @user)
  96. visit invitation_path(@invitation)
  97. end
  98. Given /^"(.*?)" has been invited to the group$/ do |email|
  99. User.invite_and_notify!(FactoryGirl.attributes_for(:user), FactoryGirl.create(:user), @group)
  100. end
  101. Given /^I am a member of a group invitable by members$/ do
  102. @group = FactoryGirl.create :group
  103. @group.members_can_add_members = true
  104. @group.save!
  105. @group.add_member! @user
  106. end
  107. Given /^the group is invitable by admins$/ do
  108. @group.members_can_add_members = false
  109. @group.save!
  110. end
  111. Given /^I am a member of a subgroup invitable by members$/ do
  112. @subgroup = FactoryGirl.create :group, parent: @group, members_can_add_members: true
  113. @subgroup.add_member!(@user)
  114. end
  115. Given /^I am a member of a subgroup invitable by admins$/ do
  116. @subgroup = FactoryGirl.create :group, parent: @group, members_can_add_members: false
  117. @subgroup.add_member!(@user)
  118. end
  119. Given /^I am an admin of a subgroup invitable by admins$/ do
  120. @subgroup = FactoryGirl.create :group, parent: @group, members_can_add_members: false
  121. @subgroup.add_admin!(@user)
  122. end
  123. When /^I invite "(.*?)" to the group$/ do |email|
  124. @current_user = User.find_by_email email
  125. click_on "group-add-members"
  126. fill_in 'user_email', with: email
  127. click_on 'invite'
  128. end
  129. When /^I visit the subgroup page$/ do
  130. visit group_path(@subgroup)
  131. end
  132. When /^I click invite people$/ do
  133. click_on 'Invite people'
  134. end
  135. When /^I select "(.*?)" from the list of members$/ do |arg1|
  136. user = User.find_by_name(arg1)
  137. find(:xpath, "//input[@value='#{user.id}']").set(true)
  138. end
  139. Then /^the request is approved$/ do
  140. @membership = Membership.last
  141. UserMailer.group_membership_approved(@membership.user, @membership.group).deliver
  142. end
  143. Then /^they should be added to the group$/ do
  144. Membership.where(:user_id => User.find_by_email(@current_user.email)).size.should > 0
  145. end
  146. Then /^I should be notified that they are already a member$/ do
  147. page.should have_content("#{@current_user.email} is already in the group.")
  148. end
  149. Then /^I should be notified that they have been invited$/ do
  150. page.should have_content("An invite has been sent")
  151. end
  152. Then /^I should be notified that the email address is invalid$/ do
  153. page.should have_content("was not invited. Please check the email address is correct.")
  154. end
  155. Then /^"(.*?)" should not be a member of the group$/ do |email|
  156. Group.find_by_name(@group.name).users.find_by_email(email).should be_nil
  157. end
  158. Then /^I should see "(.*?)" listed in the invited list$/ do |email|
  159. find("#invited-users").should have_content(email)
  160. end
  161. Then /^I should not see the add member button$/ do
  162. page.should_not have_content("#group-add-members")
  163. end
  164. Then /^I should not see the invited user list$/ do
  165. page.should_not have_css("#invited-users")
  166. end
  167. Then /^I should see "(.*?)" in the list$/ do |email|
  168. find("#invite-subgroup-members").should have_content(email)
  169. end
  170. Then /^I should not see "(.*?)" in the list$/ do |email|
  171. find("#invite-subgroup-members").should_not have_content(email)
  172. end
  173. Then /^I should see "(.*?)" as an invited user of the subgroup$/ do |email|
  174. find("#invited-users").should have_content(email)
  175. end
  176. Then /^I should see "(.*?)" as a member of the subgroup$/ do |name|
  177. visit group_memberships_path(@group)
  178. page.should have_content(name)
  179. end
  180. Then /^I should get an email with subject "(.*?)"$/ do |arg1|
  181. last_email = ActionMailer::Base.deliveries.last
  182. last_email.subject.should =~ /Membership approved/
  183. end
  184. When(/^I confirm the selection$/) do
  185. find("#invite-to-group").click
  186. end
  187. Then(/^"(.*?)" should receive a notification that they have been added$/) do |arg1|
  188. user = User.find_by_name(arg1)
  189. Notification.where(user_id: user.id).last.event.kind.should == 'user_added_to_group'
  190. end
  191. When(/^I enter "(.*?)" in the invitations field$/) do |arg1|
  192. fill_in "invitees", with: arg1
  193. end
  194. Then(/^"(.*?)" should be invited to join the subgroup$/) do |arg1|
  195. last_email = ActionMailer::Base.deliveries.last
  196. last_email.to.should == [arg1]
  197. last_email.subject.should =~ /invited you to join/
  198. end
  199. Given(/^I am a coordinator of a hidden subgroup with hidden parent$/) do
  200. @parent_group = FactoryGirl.create :group, privacy: "hidden"
  201. @parent_group.add_member! @user
  202. @subgroup = FactoryGirl.create :group, parent: @parent_group, privacy: "hidden"
  203. @subgroup.add_admin! @user
  204. end
  205. Then(/^I should not see the invitations field$/) do
  206. page.should_not have_css("#invitees")
  207. end
  208. When(/^I visit a discussion page$/) do
  209. @discussion = create_discussion group: @group, author: @group_admin
  210. visit discussion_path(@discussion)
  211. end
  212. When(/^I invite "(.*?)" to join the discussion$/) do |arg1|
  213. fill_in "invitees", with: arg1
  214. click_on 'Invite people'
  215. end
  216. Then (/^"(.*?)" should get an invitation to join the discussion$/) do |arg1|
  217. last_email = ActionMailer::Base.deliveries.last
  218. last_email.to.should == [arg1]
  219. end
  220. Given(/^I am invited to join a discussion$/) do
  221. @group_admin = FactoryGirl.create(:user)
  222. @group = FactoryGirl.create(:group)
  223. @group.add_admin! @group_admin
  224. @discussion = create_discussion group: @group, author: @group_admin
  225. @invite_people_form = InvitePeopleForm.new(recipients: ['jim@jam.com'], message_body: 'please click the invitation link below')
  226. InvitationService.invite_to_discussion(recipient_emails: @invite_people_form.recipients, message: @invite_people_form.message_body, discussion: @discussion, inviter: @group_admin)
  227. end
  228. Then(/^I should be redirected to the discussion page$/) do
  229. page.should have_css('body.discussions.show')
  230. end