From ee877888b3082a512044523a97183b938a945422 Mon Sep 17 00:00:00 2001 From: Adan Amarillas Date: Sat, 26 May 2018 21:17:08 -0700 Subject: [PATCH 1/2] Split spec common actions support helper --- spec/support/common_actions.rb | 380 +------------------ spec/support/common_actions/budgets.rb | 17 + spec/support/common_actions/comments.rb | 43 +++ spec/support/common_actions/debates.rb | 9 + spec/support/common_actions/emails.rb | 28 ++ spec/support/common_actions/notifications.rb | 84 ++++ spec/support/common_actions/polls.rb | 41 ++ spec/support/common_actions/proposals.rb | 32 ++ spec/support/common_actions/tags.rb | 6 + spec/support/common_actions/users.rb | 113 ++++++ spec/support/common_actions/verifications.rb | 77 ++++ spec/support/common_actions/votes.rb | 32 ++ 12 files changed, 495 insertions(+), 367 deletions(-) create mode 100644 spec/support/common_actions/budgets.rb create mode 100644 spec/support/common_actions/comments.rb create mode 100644 spec/support/common_actions/debates.rb create mode 100644 spec/support/common_actions/emails.rb create mode 100644 spec/support/common_actions/notifications.rb create mode 100644 spec/support/common_actions/polls.rb create mode 100644 spec/support/common_actions/proposals.rb create mode 100644 spec/support/common_actions/tags.rb create mode 100644 spec/support/common_actions/users.rb create mode 100644 spec/support/common_actions/verifications.rb create mode 100644 spec/support/common_actions/votes.rb diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index fb077c264..e5b7ece1a 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -1,369 +1,15 @@ +Dir["./spec/support/common_actions/*.rb"].each { |f| require f } + module CommonActions - - def sign_up(email = 'manuela@consul.dev', password = 'judgementday') - visit '/' - - click_link 'Register' - - fill_in 'user_username', with: "Manuela Carmena #{rand(99999)}" - fill_in 'user_email', with: email - fill_in 'user_password', with: password - fill_in 'user_password_confirmation', with: password - check 'user_terms_of_service' - - click_button 'Register' - end - - def login_through_form_with_email_and_password(email='manuela@consul.dev', password='judgementday') - visit root_path - click_link 'Sign in' - - fill_in 'user_login', with: email - fill_in 'user_password', with: password - - click_button 'Enter' - end - - def login_through_form_as(user) - visit root_path - click_link 'Sign in' - - fill_in 'user_login', with: user.email - fill_in 'user_password', with: user.password - - click_button 'Enter' - end - - def login_through_form_as_officer(user) - visit root_path - click_link 'Sign in' - - fill_in 'user_login', with: user.email - fill_in 'user_password', with: user.password - - click_button 'Enter' - visit new_officing_residence_path - end - - def login_as_authenticated_manager - expected_response = {login: login, user_key: user_key, date: date}.with_indifferent_access - login, user_key, date = "JJB042", "31415926", Time.current.strftime("%Y%m%d%H%M%S") - allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(expected_response) - visit management_sign_in_path(login: login, clave_usuario: user_key, fecha_conexion: date) - end - - def login_as_manager - manager = create(:manager) - login_as(manager.user) - visit management_sign_in_path - end - - def login_managed_user(user) - allow_any_instance_of(Management::BaseController).to receive(:managed_user).and_return(user) - end - - def confirm_email - body = ActionMailer::Base.deliveries.last.try(:body) - expect(body).to be_present - - sent_token = /.*confirmation_token=(.*)".*/.match(body.to_s)[1] - visit user_confirmation_path(confirmation_token: sent_token) - - expect(page).to have_content "Your account has been confirmed" - end - - def reset_password - create(:user, email: 'manuela@consul.dev') - - visit '/' - click_link 'Sign in' - click_link 'Forgotten your password?' - - fill_in 'user_email', with: 'manuela@consul.dev' - click_button 'Send instructions' - end - - def comment_on(commentable, user = nil) - user ||= create(:user) - - comment = create(:comment, commentable: commentable, user: user) - CommentNotifier.new(comment: comment).process - end - - def reply_to(original_user, manuela = nil) - manuela ||= create(:user) - - debate = create(:debate) - comment = create(:comment, commentable: debate, user: original_user) - - login_as(manuela) - visit debate_path(debate) - - click_link "Reply" - within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' - click_button 'Publish reply' - end - expect(page).to have_content 'It will be done next week.' - end - - def avatar(name) - "img.initialjs-avatar[data-name='#{name}']" - end - - # Used to fill ckeditor fields - # @param [String] locator label text for the textarea or textarea id - def fill_in_ckeditor(locator, params = {}) - # Find out ckeditor id at runtime using its label - locator = find('label', text: locator)[:for] if page.has_css?('label', text: locator) - # Fill the editor content - page.execute_script <<-SCRIPT - var ckeditor = CKEDITOR.instances.#{locator} - ckeditor.setData('#{params[:with]}') - ckeditor.focus() - ckeditor.updateElement() - SCRIPT - end - - def error_message(resource_model = nil) - resource_model ||= "(.*)" - field_check_message = 'Please check the marked fields to know how to correct them:' - /\d errors? prevented this #{resource_model} from being saved. #{field_check_message}/ - end - - def expect_to_be_signed_in - expect(find('.top-bar')).to have_content 'My account' - end - - def expect_to_not_be_signed_in - expect(find('.top-bar')).not_to have_content 'My account' - end - - def select_date(values, selector) - selector = selector[:from] - day, month, year = values.split("-") - select day, from: "#{selector}_3i" - select month, from: "#{selector}_2i" - select year, from: "#{selector}_1i" - end - - def verify_residence - select 'DNI', from: 'residence_document_type' - fill_in 'residence_document_number', with: "12345678Z" - select_date '31-December-1980', from: 'residence_date_of_birth' - fill_in 'residence_postal_code', with: '28013' - check 'residence_terms_of_service' - - click_button 'Verify residence' - expect(page).to have_content 'Residence verified' - end - - def officing_verify_residence - select 'DNI', from: 'residence_document_type' - fill_in 'residence_document_number', with: "12345678Z" - fill_in 'residence_year_of_birth', with: "1980" - - click_button 'Validate document' - - expect(page).to have_content 'Document verified with Census' - end - - def confirm_phone(user = nil) - user ||= User.last - - fill_in 'sms_phone', with: "611111111" - click_button 'Send' - - expect(page).to have_content 'Enter the confirmation code sent to you by text message' - - fill_in 'sms_confirmation_code', with: user.reload.sms_confirmation_code - click_button 'Send' - - expect(page).to have_content 'Code correct' - end - - def expect_message_you_need_to_sign_in - expect(page).to have_content 'You must Sign in or Sign up to continue' - expect(page).to have_selector('.in-favor', visible: false) - end - - def expect_message_you_need_to_sign_in_to_vote_comments - expect(page).to have_content 'You must Sign in or Sign up to vote' - expect(page).to have_selector('.participation-allowed', visible: false) - expect(page).to have_selector('.participation-not-allowed', visible: true) - end - - def expect_message_to_many_anonymous_votes - expect(page).to have_content 'Too many anonymous votes to admit vote' - expect(page).to have_selector('.in-favor a', visible: false) - end - - def expect_message_only_verified_can_vote_proposals - expect(page).to have_content 'Only verified users can vote on proposals' - expect(page).to have_selector('.in-favor', visible: false) - end - - def expect_message_voting_not_allowed - expect(page).to have_content 'Voting phase is closed' - expect(page).not_to have_selector('.in-favor a') - end - - def expect_message_selecting_not_allowed - expect(page).to have_content 'No Selecting Allowed' - expect(page).not_to have_selector('.in-favor a') - end - - def expect_message_organizations_cannot_vote - #expect(page).to have_content 'Organisations are not permitted to vote.' - expect(page).to have_content 'Organization' - expect(page).to have_selector('.in-favor a', visible: false) - end - - def create_featured_proposals - [create(:proposal, :with_confidence_score, cached_votes_up: 100), - create(:proposal, :with_confidence_score, cached_votes_up: 90), - create(:proposal, :with_confidence_score, cached_votes_up: 80)] - end - - def create_featured_debates - [create(:debate, :with_confidence_score, cached_votes_up: 100), - create(:debate, :with_confidence_score, cached_votes_up: 90), - create(:debate, :with_confidence_score, cached_votes_up: 80)] - end - - def create_successful_proposals - [create(:proposal, title: "Winter is coming", question: "Do you speak it?", - cached_votes_up: Proposal.votes_needed_for_success + 100), - create(:proposal, title: "Fire and blood", question: "You talking to me?", - cached_votes_up: Proposal.votes_needed_for_success + 1)] - end - - def create_archived_proposals - months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i - [ - create(:proposal, title: "This is an expired proposal", - created_at: months_to_archive_proposals.months.ago), - create(:proposal, title: "This is an oldest expired proposal", - created_at: (months_to_archive_proposals + 2).months.ago) - ] - end - - def tag_names(tag_cloud) - tag_cloud.tags.map(&:name) - end - - def create_proposal_notification(proposal) - login_as(proposal.author) - visit root_path - - click_link "My activity" - - within("#proposal_#{proposal.id}") do - click_link "Send notification" - end - - fill_in 'proposal_notification_title', with: "Thanks for supporting proposal: #{proposal.title}" - fill_in 'proposal_notification_body', with: "Please share it with others! #{proposal.summary}" - click_button "Send message" - - expect(page).to have_content "Your message has been sent correctly." - Notification.last - end - - def create_direct_message(sender, receiver) - login_as(sender) - visit user_path(receiver) - - click_link "Send private message" - - expect(page).to have_content "Send private message to #{receiver.name}" - - fill_in 'direct_message_title', with: "Hey #{receiver.name}!" - fill_in 'direct_message_body', with: "How are you doing? This is #{sender.name}" - - click_button "Send message" - - expect(page).to have_content "You message has been sent successfully." - DirectMessage.last - end - - def expect_badge_for(resource_name, resource) - within("##{resource_name}_#{resource.id}") do - expect(page).to have_css ".label.round" - expect(page).to have_content "Employee" - end - end - - def expect_no_badge_for(resource_name, resource) - within("##{resource_name}_#{resource.id}") do - expect(page).not_to have_css ".label.round" - expect(page).not_to have_content "Employee" - end - end - - def add_to_ballot(budget_investment) - within("#budget_investment_#{budget_investment.id}") do - find('.add a').click - expect(page).to have_content "Remove" - end - end - - def vote_for_poll_via_web(poll, question, answer) - visit poll_path(poll) - - within("#poll_question_#{question.id}_answers") do - click_link answer.to_s - expect(page).not_to have_link(answer.to_s) - end - end - - def vote_for_poll_via_booth - visit new_officing_residence_path - officing_verify_residence - - expect(page).to have_content poll.name - - first(:button, "Confirm vote").click - expect(page).to have_content "Vote introduced!" - - expect(Poll::Voter.count).to eq(1) - end - - def model_name(described_class) - return :proposal_notification if described_class == ProposalNotification - - described_class.name.gsub("::", "_").downcase.to_sym - end - - def comment_body(resource) - "comment-body-#{resource.class.name.parameterize('_').to_sym}_#{resource.id}" - end - - def path_for(resource) - nested_path_for(resource) || url_for([resource, only_path: true]) - end - - def nested_path_for(resource) - case resource.class.name - when "Legislation::Question" - legislation_process_question_path(resource.process, resource) - when "Legislation::Proposal" - legislation_process_proposal_path(resource.process, resource) - when "Budget::Investment" - budget_investment_path(resource.budget, resource) - else - false - end - end - - def fill_in_newsletter_form(options = {}) - fill_in "newsletter_subject", with: (options[:subject] || "This is a different subject") - select (options[:segment_recipient] || 'All users'), from: 'newsletter_segment_recipient' - fill_in "newsletter_from", with: (options[:from] || "no-reply@consul.dev") - fill_in "newsletter_body", with: (options[:body] || "This is a different body") - end - - def click_notifications_icon - find("#notifications a").click - end + include Budgets + include Comments + include Debates + include Emails + include Notifications + include Polls + include Proposals + include Tags + include Users + include Verifications + include Votes end diff --git a/spec/support/common_actions/budgets.rb b/spec/support/common_actions/budgets.rb new file mode 100644 index 000000000..eecb47cd1 --- /dev/null +++ b/spec/support/common_actions/budgets.rb @@ -0,0 +1,17 @@ +module Budgets + # spec/features/budgets/ballots_spec.rb + def expect_message_organizations_cannot_vote + #expect(page).to have_content 'Organisations are not permitted to vote.' + expect(page).to have_content 'Organization' + expect(page).to have_selector('.in-favor a', visible: false) + end + + # spec/features/budgets/ballots_spec.rb + # spec/features/budgets/investments_spec.rb + def add_to_ballot(budget_investment) + within("#budget_investment_#{budget_investment.id}") do + find('.add a').click + expect(page).to have_content "Remove" + end + end +end diff --git a/spec/support/common_actions/comments.rb b/spec/support/common_actions/comments.rb new file mode 100644 index 000000000..63c5efb7b --- /dev/null +++ b/spec/support/common_actions/comments.rb @@ -0,0 +1,43 @@ +module Comments + # spec/features/emails_spec.rb + # spec/models/vote_spec.rb + def comment_on(commentable, user = nil) + user ||= create(:user) + + comment = create(:comment, commentable: commentable, user: user) + CommentNotifier.new(comment: comment).process + end + + # spec/features/emails_spec.rb + def reply_to(original_user, manuela = nil) + manuela ||= create(:user) + + debate = create(:debate) + comment = create(:comment, commentable: debate, user: original_user) + + login_as(manuela) + visit debate_path(debate) + + click_link "Reply" + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' + click_button 'Publish reply' + end + expect(page).to have_content 'It will be done next week.' + end + + # spec/features/account_spec.rb + # spec/features/comments/budget_investments_spec.rb + # spec/features/comments/budget_investments_valuation_spec.rb + # spec/features/comments/debates_spec.rb + # spec/features/comments/legislation_annotations_spec.rb + # spec/features/comments/legislation_questions_spec.rb + # spec/features/comments/polls_spec.rb + # spec/features/comments/proposals_spec.rb + # spec/features/comments/topics_spec.rb + # spec/features/debates_spec.rb + # spec/features/proposals_spec.rb + def avatar(name) + "img.initialjs-avatar[data-name='#{name}']" + end +end diff --git a/spec/support/common_actions/debates.rb b/spec/support/common_actions/debates.rb new file mode 100644 index 000000000..edf6ad96a --- /dev/null +++ b/spec/support/common_actions/debates.rb @@ -0,0 +1,9 @@ +module Debates + # spec/features/debates_spec.rb + # spec/features/tags/debates_spec.rb + def create_featured_debates + [create(:debate, :with_confidence_score, cached_votes_up: 100), + create(:debate, :with_confidence_score, cached_votes_up: 90), + create(:debate, :with_confidence_score, cached_votes_up: 80)] + end +end diff --git a/spec/support/common_actions/emails.rb b/spec/support/common_actions/emails.rb new file mode 100644 index 000000000..2cbc3c1cb --- /dev/null +++ b/spec/support/common_actions/emails.rb @@ -0,0 +1,28 @@ +module Emails + # spec/features/emails_spec.rb + def create_direct_message(sender, receiver) + login_as(sender) + visit user_path(receiver) + + click_link "Send private message" + + expect(page).to have_content "Send private message to #{receiver.name}" + + fill_in 'direct_message_title', with: "Hey #{receiver.name}!" + fill_in 'direct_message_body', with: "How are you doing? This is #{sender.name}" + + click_button "Send message" + + expect(page).to have_content "You message has been sent successfully." + DirectMessage.last + end + + # spec/features/admin/emails/newsletters_spec.rb + # spec/features/emails_spec.rb + def fill_in_newsletter_form(options = {}) + fill_in "newsletter_subject", with: (options[:subject] || "This is a different subject") + select (options[:segment_recipient] || 'All users'), from: 'newsletter_segment_recipient' + fill_in "newsletter_from", with: (options[:from] || "no-reply@consul.dev") + fill_in "newsletter_body", with: (options[:body] || "This is a different body") + end +end diff --git a/spec/support/common_actions/notifications.rb b/spec/support/common_actions/notifications.rb new file mode 100644 index 000000000..7b8d988bd --- /dev/null +++ b/spec/support/common_actions/notifications.rb @@ -0,0 +1,84 @@ +module Notifications + # spec/features/notifications_spec.rb + def click_notifications_icon + find("#notifications a").click + end + + # spec/models/proposal_notification_spec.rb + # spec/shared/features/followable.rb + # spec/shared/features/notifiable_in_app.rb + # spec/shared/features/relationable.rb + # spec/shared/models/map_validations.rb + # spec/shared/models/notifiable.rb + def model_name(described_class) + return :proposal_notification if described_class == ProposalNotification + + described_class.name.gsub("::", "_").downcase.to_sym + end + + # spec/shared/features/notifiable_in_app.rb + def comment_body(resource) + "comment-body-#{resource.class.name.parameterize('_').to_sym}_#{resource.id}" + end + + # spec/features/emails_spec.rb + # spec/features/proposal_notifications_spec.rb + def create_proposal_notification(proposal) + login_as(proposal.author) + visit root_path + + click_link "My activity" + + within("#proposal_#{proposal.id}") do + click_link "Send notification" + end + + fill_in 'proposal_notification_title', with: "Thanks for supporting proposal: #{proposal.title}" + fill_in 'proposal_notification_body', with: "Please share it with others! #{proposal.summary}" + click_button "Send message" + + expect(page).to have_content "Your message has been sent correctly." + Notification.last + end + + # spec/shared/features/notifiable_in_app.rb + def path_for(resource) + nested_path_for(resource) || url_for([resource, only_path: true]) + end + + # Used locally by method 'path_for' + def nested_path_for(resource) + case resource.class.name + when "Legislation::Question" + legislation_process_question_path(resource.process, resource) + when "Legislation::Proposal" + legislation_process_proposal_path(resource.process, resource) + when "Budget::Investment" + budget_investment_path(resource.budget, resource) + else + false + end + end + + # spec/features/account_spec.rb + # spec/features/admin/emails/newsletters_spec.rb + # spec/features/admin/signature_sheets_spec.rb + # spec/features/budgets/investments_spec.rb + # spec/features/debates_spec.rb + # spec/features/direct_messages_spec.rb + # spec/features/organizations_spec.rb + # spec/features/proposal_notifications_spec.rb + # spec/features/proposals_spec.rb + # spec/features/tags_spec.rb + # spec/features/tags/budget_investments_spec.rb + # spec/features/tags/debates_spec.rb + # spec/features/tags/proposals_spec.rb + # spec/features/users_auth_spec.rb + # spec/features/verification/sms_spec.rb + # spec/shared/models/document_validations.rb + def error_message(resource_model = nil) + resource_model ||= "(.*)" + field_check_message = 'Please check the marked fields to know how to correct them:' + /\d errors? prevented this #{resource_model} from being saved. #{field_check_message}/ + end +end diff --git a/spec/support/common_actions/polls.rb b/spec/support/common_actions/polls.rb new file mode 100644 index 000000000..2bcb591e0 --- /dev/null +++ b/spec/support/common_actions/polls.rb @@ -0,0 +1,41 @@ +module Polls + # spec/features/polls/results_spec.rb + # spec/features/polls/voter_spec.rb + def vote_for_poll_via_web(poll, question, answer) + visit poll_path(poll) + + within("#poll_question_#{question.id}_answers") do + click_link answer.to_s + expect(page).not_to have_link(answer.to_s) + end + end + + # spec/features/polls/voter_spec.rb + def vote_for_poll_via_booth + visit new_officing_residence_path + officing_verify_residence + + expect(page).to have_content poll.name + + first(:button, "Confirm vote").click + expect(page).to have_content "Vote introduced!" + + expect(Poll::Voter.count).to eq(1) + end + + # spec/features/admin/stats_spec.rb + # spec/features/polls/voter_spec.rb + def confirm_phone(user = nil) + user ||= User.last + + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + + expect(page).to have_content 'Enter the confirmation code sent to you by text message' + + fill_in 'sms_confirmation_code', with: user.reload.sms_confirmation_code + click_button 'Send' + + expect(page).to have_content 'Code correct' + end +end diff --git a/spec/support/common_actions/proposals.rb b/spec/support/common_actions/proposals.rb new file mode 100644 index 000000000..c540c2150 --- /dev/null +++ b/spec/support/common_actions/proposals.rb @@ -0,0 +1,32 @@ +module Proposals + # spec/features/proposal_ballots_spec.rb + # spec/features/proposals_spec.rb + def create_successful_proposals + [create(:proposal, title: "Winter is coming", question: "Do you speak it?", + cached_votes_up: Proposal.votes_needed_for_success + 100), + create(:proposal, title: "Fire and blood", question: "You talking to me?", + cached_votes_up: Proposal.votes_needed_for_success + 1)] + end + + # spec/features/proposals_spec.rb + def create_archived_proposals + months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i + [ + create(:proposal, title: "This is an expired proposal", + created_at: months_to_archive_proposals.months.ago), + create(:proposal, title: "This is an oldest expired proposal", + created_at: (months_to_archive_proposals + 2).months.ago) + ] + end + + # spec/features/official_positions_spec.rb + # spec/features/proposals_spec.rb + # spec/features/tags/budget_investments_spec.rb + # spec/features/tags/proposals_spec.rb + # spec/features/votes_spec.rb + def create_featured_proposals + [create(:proposal, :with_confidence_score, cached_votes_up: 100), + create(:proposal, :with_confidence_score, cached_votes_up: 90), + create(:proposal, :with_confidence_score, cached_votes_up: 80)] + end +end diff --git a/spec/support/common_actions/tags.rb b/spec/support/common_actions/tags.rb new file mode 100644 index 000000000..b77ce4ab7 --- /dev/null +++ b/spec/support/common_actions/tags.rb @@ -0,0 +1,6 @@ +module Tags + # spec/models/tag_cloud_spec.rb + def tag_names(tag_cloud) + tag_cloud.tags.map(&:name) + end +end diff --git a/spec/support/common_actions/users.rb b/spec/support/common_actions/users.rb new file mode 100644 index 000000000..ef1017ad1 --- /dev/null +++ b/spec/support/common_actions/users.rb @@ -0,0 +1,113 @@ +module Users + # spec/features/email_spec.rb + def sign_up(email = 'manuela@consul.dev', password = 'judgementday') + visit '/' + + click_link 'Register' + + fill_in 'user_username', with: "Manuela Carmena #{rand(99999)}" + fill_in 'user_email', with: email + fill_in 'user_password', with: password + fill_in 'user_password_confirmation', with: password + check 'user_terms_of_service' + + click_button 'Register' + end + + # spec/features/management/account_spec.rb + def login_through_form_with_email_and_password(email='manuela@consul.dev', password='judgementday') + visit root_path + click_link 'Sign in' + + fill_in 'user_login', with: email + fill_in 'user_password', with: password + + click_button 'Enter' + end + + # spec/features/account_spec.rb + # spec/features/polls/voter_spec.rb + # spec/features/sessions_spec.rb + # spec/features/welcome_spec.rb + def login_through_form_as(user) + visit root_path + click_link 'Sign in' + + fill_in 'user_login', with: user.email + fill_in 'user_password', with: user.password + + click_button 'Enter' + end + + # spec/features/polls/voter_spec.rb + def login_through_form_as_officer(user) + visit root_path + click_link 'Sign in' + + fill_in 'user_login', with: user.email + fill_in 'user_password', with: user.password + + click_button 'Enter' + visit new_officing_residence_path + end + + + # spec/features/email_spec.rb + # spec/features/management/account_spec.rb + # spec/features/management/account_spec.rb + # spec/features/management/budget_investments_spec.rb + # spec/features/management/document_verifications_spec.rb + # spec/features/management/email_verifications_spec.rb + # spec/features/management/localization_spec.rb + # spec/features/management/managed_users_spec.rb + # spec/features/management/proposals_spec.rb + # spec/features/management/users_spec.rb + # spec/features/user_invites_spec.rb + def login_as_manager + manager = create(:manager) + login_as(manager.user) + visit management_sign_in_path + end + + # spec/features/management/account_spec.rb + # spec/features/management/budget_investments_spec.rb + # spec/features/management/proposals_spec.rb + def login_managed_user(user) + allow_any_instance_of(Management::BaseController).to receive(:managed_user).and_return(user) + end + + # spec/features/users_auth_spec.rb + def confirm_email + body = ActionMailer::Base.deliveries.last.try(:body) + expect(body).to be_present + + sent_token = /.*confirmation_token=(.*)".*/.match(body.to_s)[1] + visit user_confirmation_path(confirmation_token: sent_token) + + expect(page).to have_content "Your account has been confirmed" + end + + # spec/features/emails_spec.rb + # spec/features/users_auth_spec.rb + # spec/models/user_spec.rb + def reset_password + create(:user, email: 'manuela@consul.dev') + + visit '/' + click_link 'Sign in' + click_link 'Forgotten your password?' + + fill_in 'user_email', with: 'manuela@consul.dev' + click_button 'Send instructions' + end + + # spec/features/users_auth_spec.rb + def expect_to_be_signed_in + expect(find('.top-bar')).to have_content 'My account' + end + + # spec/features/users_auth_spec.rb + def expect_to_not_be_signed_in + expect(find('.top-bar')).not_to have_content 'My account' + end +end diff --git a/spec/support/common_actions/verifications.rb b/spec/support/common_actions/verifications.rb new file mode 100644 index 000000000..0219a036c --- /dev/null +++ b/spec/support/common_actions/verifications.rb @@ -0,0 +1,77 @@ +module Verifications + # spec/features/management/users_spec.rb + # spec/features/verification/residence_spec.rb + def select_date(values, selector) + selector = selector[:from] + day, month, year = values.split("-") + select day, from: "#{selector}_3i" + select month, from: "#{selector}_2i" + select year, from: "#{selector}_1i" + end + + # spec/features/admin/stats_spec.rb + # spec/features/officing/voters_spec.rb + # spec/features/polls/polls_spec.rb + # spec/features/polls/voter_spec.rb + # spec/features/tracks_spec.rb + # spec/features/verification/level_three_verification_spec.rb + # spec/features/verification/level_two_verification_spec.rb + def verify_residence + select 'DNI', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + select_date '31-December-1980', from: 'residence_date_of_birth' + fill_in 'residence_postal_code', with: '28013' + check 'residence_terms_of_service' + + click_button 'Verify residence' + expect(page).to have_content 'Residence verified' + end + + # spec/features/officing/voters_spec.rb + # spec/features/polls/polls_spec.rb + # spec/features/polls/voter_spec.rb + def officing_verify_residence + select 'DNI', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + fill_in 'residence_year_of_birth', with: "1980" + + click_button 'Validate document' + + expect(page).to have_content 'Document verified with Census' + end + + # spec/features/official_positions_spec.rb + def expect_badge_for(resource_name, resource) + within("##{resource_name}_#{resource.id}") do + expect(page).to have_css ".label.round" + expect(page).to have_content "Employee" + end + end + + # spec/features/official_positions_spec.rb + def expect_no_badge_for(resource_name, resource) + within("##{resource_name}_#{resource.id}") do + expect(page).not_to have_css ".label.round" + expect(page).not_to have_content "Employee" + end + end + + # spec/features/tags/budget_investments_spec.rb + # spec/features/tags/proposals_spec.rb + # spec/shared/features/mappable.rb + # spec/shared/features/nested_documentable.rb + # spec/shared/features/nested_imageable.rb + # Used to fill ckeditor fields + # @param [String] locator label text for the textarea or textarea id + def fill_in_ckeditor(locator, params = {}) + # Find out ckeditor id at runtime using its label + locator = find('label', text: locator)[:for] if page.has_css?('label', text: locator) + # Fill the editor content + page.execute_script <<-SCRIPT + var ckeditor = CKEDITOR.instances.#{locator} + ckeditor.setData('#{params[:with]}') + ckeditor.focus() + ckeditor.updateElement() + SCRIPT + end +end diff --git a/spec/support/common_actions/votes.rb b/spec/support/common_actions/votes.rb new file mode 100644 index 000000000..21c2e61f5 --- /dev/null +++ b/spec/support/common_actions/votes.rb @@ -0,0 +1,32 @@ +module Votes + # spec/features/votes_spec.rb + def expect_message_you_need_to_sign_in + expect(page).to have_content 'You must Sign in or Sign up to continue' + expect(page).to have_selector('.in-favor', visible: false) + end + + # spec/features/votes_spec.rb + def expect_message_you_need_to_sign_in_to_vote_comments + expect(page).to have_content 'You must Sign in or Sign up to vote' + expect(page).to have_selector('.participation-allowed', visible: false) + expect(page).to have_selector('.participation-not-allowed', visible: true) + end + + # spec/features/votes_spec.rb + def expect_message_to_many_anonymous_votes + expect(page).to have_content 'Too many anonymous votes to admit vote' + expect(page).to have_selector('.in-favor a', visible: false) + end + + # spec/features/votes_spec.rb + def expect_message_only_verified_can_vote_proposals + expect(page).to have_content 'Only verified users can vote on proposals' + expect(page).to have_selector('.in-favor', visible: false) + end + + # spec/features/votes_spec.rb + def expect_message_voting_not_allowed + expect(page).to have_content 'Voting phase is closed' + expect(page).not_to have_selector('.in-favor a') + end +end From 9210d8928e91f49809097f0b3874037dec0cca47 Mon Sep 17 00:00:00 2001 From: Adan Amarillas Date: Mon, 4 Jun 2018 08:54:17 -0700 Subject: [PATCH 2/2] Clean up newly created modules --- spec/support/common_actions/budgets.rb | 4 --- spec/support/common_actions/comments.rb | 16 +---------- spec/support/common_actions/debates.rb | 2 -- spec/support/common_actions/emails.rb | 3 --- spec/support/common_actions/notifications.rb | 28 -------------------- spec/support/common_actions/polls.rb | 5 ---- spec/support/common_actions/proposals.rb | 8 ------ spec/support/common_actions/tags.rb | 1 - spec/support/common_actions/users.rb | 28 -------------------- spec/support/common_actions/verifications.rb | 20 -------------- spec/support/common_actions/votes.rb | 5 ---- 11 files changed, 1 insertion(+), 119 deletions(-) diff --git a/spec/support/common_actions/budgets.rb b/spec/support/common_actions/budgets.rb index eecb47cd1..97d4a53d5 100644 --- a/spec/support/common_actions/budgets.rb +++ b/spec/support/common_actions/budgets.rb @@ -1,13 +1,9 @@ module Budgets - # spec/features/budgets/ballots_spec.rb def expect_message_organizations_cannot_vote - #expect(page).to have_content 'Organisations are not permitted to vote.' expect(page).to have_content 'Organization' expect(page).to have_selector('.in-favor a', visible: false) end - # spec/features/budgets/ballots_spec.rb - # spec/features/budgets/investments_spec.rb def add_to_ballot(budget_investment) within("#budget_investment_#{budget_investment.id}") do find('.add a').click diff --git a/spec/support/common_actions/comments.rb b/spec/support/common_actions/comments.rb index 63c5efb7b..16683649b 100644 --- a/spec/support/common_actions/comments.rb +++ b/spec/support/common_actions/comments.rb @@ -1,6 +1,4 @@ module Comments - # spec/features/emails_spec.rb - # spec/models/vote_spec.rb def comment_on(commentable, user = nil) user ||= create(:user) @@ -8,7 +6,6 @@ module Comments CommentNotifier.new(comment: comment).process end - # spec/features/emails_spec.rb def reply_to(original_user, manuela = nil) manuela ||= create(:user) @@ -25,18 +22,7 @@ module Comments end expect(page).to have_content 'It will be done next week.' end - - # spec/features/account_spec.rb - # spec/features/comments/budget_investments_spec.rb - # spec/features/comments/budget_investments_valuation_spec.rb - # spec/features/comments/debates_spec.rb - # spec/features/comments/legislation_annotations_spec.rb - # spec/features/comments/legislation_questions_spec.rb - # spec/features/comments/polls_spec.rb - # spec/features/comments/proposals_spec.rb - # spec/features/comments/topics_spec.rb - # spec/features/debates_spec.rb - # spec/features/proposals_spec.rb + def avatar(name) "img.initialjs-avatar[data-name='#{name}']" end diff --git a/spec/support/common_actions/debates.rb b/spec/support/common_actions/debates.rb index edf6ad96a..68488c348 100644 --- a/spec/support/common_actions/debates.rb +++ b/spec/support/common_actions/debates.rb @@ -1,6 +1,4 @@ module Debates - # spec/features/debates_spec.rb - # spec/features/tags/debates_spec.rb def create_featured_debates [create(:debate, :with_confidence_score, cached_votes_up: 100), create(:debate, :with_confidence_score, cached_votes_up: 90), diff --git a/spec/support/common_actions/emails.rb b/spec/support/common_actions/emails.rb index 2cbc3c1cb..cbf3ec441 100644 --- a/spec/support/common_actions/emails.rb +++ b/spec/support/common_actions/emails.rb @@ -1,5 +1,4 @@ module Emails - # spec/features/emails_spec.rb def create_direct_message(sender, receiver) login_as(sender) visit user_path(receiver) @@ -17,8 +16,6 @@ module Emails DirectMessage.last end - # spec/features/admin/emails/newsletters_spec.rb - # spec/features/emails_spec.rb def fill_in_newsletter_form(options = {}) fill_in "newsletter_subject", with: (options[:subject] || "This is a different subject") select (options[:segment_recipient] || 'All users'), from: 'newsletter_segment_recipient' diff --git a/spec/support/common_actions/notifications.rb b/spec/support/common_actions/notifications.rb index 7b8d988bd..4ae98c3d0 100644 --- a/spec/support/common_actions/notifications.rb +++ b/spec/support/common_actions/notifications.rb @@ -1,28 +1,18 @@ module Notifications - # spec/features/notifications_spec.rb def click_notifications_icon find("#notifications a").click end - # spec/models/proposal_notification_spec.rb - # spec/shared/features/followable.rb - # spec/shared/features/notifiable_in_app.rb - # spec/shared/features/relationable.rb - # spec/shared/models/map_validations.rb - # spec/shared/models/notifiable.rb def model_name(described_class) return :proposal_notification if described_class == ProposalNotification described_class.name.gsub("::", "_").downcase.to_sym end - # spec/shared/features/notifiable_in_app.rb def comment_body(resource) "comment-body-#{resource.class.name.parameterize('_').to_sym}_#{resource.id}" end - # spec/features/emails_spec.rb - # spec/features/proposal_notifications_spec.rb def create_proposal_notification(proposal) login_as(proposal.author) visit root_path @@ -41,12 +31,10 @@ module Notifications Notification.last end - # spec/shared/features/notifiable_in_app.rb def path_for(resource) nested_path_for(resource) || url_for([resource, only_path: true]) end - # Used locally by method 'path_for' def nested_path_for(resource) case resource.class.name when "Legislation::Question" @@ -60,22 +48,6 @@ module Notifications end end - # spec/features/account_spec.rb - # spec/features/admin/emails/newsletters_spec.rb - # spec/features/admin/signature_sheets_spec.rb - # spec/features/budgets/investments_spec.rb - # spec/features/debates_spec.rb - # spec/features/direct_messages_spec.rb - # spec/features/organizations_spec.rb - # spec/features/proposal_notifications_spec.rb - # spec/features/proposals_spec.rb - # spec/features/tags_spec.rb - # spec/features/tags/budget_investments_spec.rb - # spec/features/tags/debates_spec.rb - # spec/features/tags/proposals_spec.rb - # spec/features/users_auth_spec.rb - # spec/features/verification/sms_spec.rb - # spec/shared/models/document_validations.rb def error_message(resource_model = nil) resource_model ||= "(.*)" field_check_message = 'Please check the marked fields to know how to correct them:' diff --git a/spec/support/common_actions/polls.rb b/spec/support/common_actions/polls.rb index 2bcb591e0..e98c9c5f3 100644 --- a/spec/support/common_actions/polls.rb +++ b/spec/support/common_actions/polls.rb @@ -1,6 +1,4 @@ module Polls - # spec/features/polls/results_spec.rb - # spec/features/polls/voter_spec.rb def vote_for_poll_via_web(poll, question, answer) visit poll_path(poll) @@ -10,7 +8,6 @@ module Polls end end - # spec/features/polls/voter_spec.rb def vote_for_poll_via_booth visit new_officing_residence_path officing_verify_residence @@ -23,8 +20,6 @@ module Polls expect(Poll::Voter.count).to eq(1) end - # spec/features/admin/stats_spec.rb - # spec/features/polls/voter_spec.rb def confirm_phone(user = nil) user ||= User.last diff --git a/spec/support/common_actions/proposals.rb b/spec/support/common_actions/proposals.rb index c540c2150..4729a2451 100644 --- a/spec/support/common_actions/proposals.rb +++ b/spec/support/common_actions/proposals.rb @@ -1,6 +1,4 @@ module Proposals - # spec/features/proposal_ballots_spec.rb - # spec/features/proposals_spec.rb def create_successful_proposals [create(:proposal, title: "Winter is coming", question: "Do you speak it?", cached_votes_up: Proposal.votes_needed_for_success + 100), @@ -8,7 +6,6 @@ module Proposals cached_votes_up: Proposal.votes_needed_for_success + 1)] end - # spec/features/proposals_spec.rb def create_archived_proposals months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i [ @@ -19,11 +16,6 @@ module Proposals ] end - # spec/features/official_positions_spec.rb - # spec/features/proposals_spec.rb - # spec/features/tags/budget_investments_spec.rb - # spec/features/tags/proposals_spec.rb - # spec/features/votes_spec.rb def create_featured_proposals [create(:proposal, :with_confidence_score, cached_votes_up: 100), create(:proposal, :with_confidence_score, cached_votes_up: 90), diff --git a/spec/support/common_actions/tags.rb b/spec/support/common_actions/tags.rb index b77ce4ab7..b94ebdbcd 100644 --- a/spec/support/common_actions/tags.rb +++ b/spec/support/common_actions/tags.rb @@ -1,5 +1,4 @@ module Tags - # spec/models/tag_cloud_spec.rb def tag_names(tag_cloud) tag_cloud.tags.map(&:name) end diff --git a/spec/support/common_actions/users.rb b/spec/support/common_actions/users.rb index ef1017ad1..93f0f0fe6 100644 --- a/spec/support/common_actions/users.rb +++ b/spec/support/common_actions/users.rb @@ -1,5 +1,4 @@ module Users - # spec/features/email_spec.rb def sign_up(email = 'manuela@consul.dev', password = 'judgementday') visit '/' @@ -14,7 +13,6 @@ module Users click_button 'Register' end - # spec/features/management/account_spec.rb def login_through_form_with_email_and_password(email='manuela@consul.dev', password='judgementday') visit root_path click_link 'Sign in' @@ -25,10 +23,6 @@ module Users click_button 'Enter' end - # spec/features/account_spec.rb - # spec/features/polls/voter_spec.rb - # spec/features/sessions_spec.rb - # spec/features/welcome_spec.rb def login_through_form_as(user) visit root_path click_link 'Sign in' @@ -39,7 +33,6 @@ module Users click_button 'Enter' end - # spec/features/polls/voter_spec.rb def login_through_form_as_officer(user) visit root_path click_link 'Sign in' @@ -51,32 +44,16 @@ module Users visit new_officing_residence_path end - - # spec/features/email_spec.rb - # spec/features/management/account_spec.rb - # spec/features/management/account_spec.rb - # spec/features/management/budget_investments_spec.rb - # spec/features/management/document_verifications_spec.rb - # spec/features/management/email_verifications_spec.rb - # spec/features/management/localization_spec.rb - # spec/features/management/managed_users_spec.rb - # spec/features/management/proposals_spec.rb - # spec/features/management/users_spec.rb - # spec/features/user_invites_spec.rb def login_as_manager manager = create(:manager) login_as(manager.user) visit management_sign_in_path end - # spec/features/management/account_spec.rb - # spec/features/management/budget_investments_spec.rb - # spec/features/management/proposals_spec.rb def login_managed_user(user) allow_any_instance_of(Management::BaseController).to receive(:managed_user).and_return(user) end - # spec/features/users_auth_spec.rb def confirm_email body = ActionMailer::Base.deliveries.last.try(:body) expect(body).to be_present @@ -87,9 +64,6 @@ module Users expect(page).to have_content "Your account has been confirmed" end - # spec/features/emails_spec.rb - # spec/features/users_auth_spec.rb - # spec/models/user_spec.rb def reset_password create(:user, email: 'manuela@consul.dev') @@ -101,12 +75,10 @@ module Users click_button 'Send instructions' end - # spec/features/users_auth_spec.rb def expect_to_be_signed_in expect(find('.top-bar')).to have_content 'My account' end - # spec/features/users_auth_spec.rb def expect_to_not_be_signed_in expect(find('.top-bar')).not_to have_content 'My account' end diff --git a/spec/support/common_actions/verifications.rb b/spec/support/common_actions/verifications.rb index 0219a036c..28364a759 100644 --- a/spec/support/common_actions/verifications.rb +++ b/spec/support/common_actions/verifications.rb @@ -1,6 +1,4 @@ module Verifications - # spec/features/management/users_spec.rb - # spec/features/verification/residence_spec.rb def select_date(values, selector) selector = selector[:from] day, month, year = values.split("-") @@ -9,13 +7,6 @@ module Verifications select year, from: "#{selector}_1i" end - # spec/features/admin/stats_spec.rb - # spec/features/officing/voters_spec.rb - # spec/features/polls/polls_spec.rb - # spec/features/polls/voter_spec.rb - # spec/features/tracks_spec.rb - # spec/features/verification/level_three_verification_spec.rb - # spec/features/verification/level_two_verification_spec.rb def verify_residence select 'DNI', from: 'residence_document_type' fill_in 'residence_document_number', with: "12345678Z" @@ -27,9 +18,6 @@ module Verifications expect(page).to have_content 'Residence verified' end - # spec/features/officing/voters_spec.rb - # spec/features/polls/polls_spec.rb - # spec/features/polls/voter_spec.rb def officing_verify_residence select 'DNI', from: 'residence_document_type' fill_in 'residence_document_number', with: "12345678Z" @@ -40,7 +28,6 @@ module Verifications expect(page).to have_content 'Document verified with Census' end - # spec/features/official_positions_spec.rb def expect_badge_for(resource_name, resource) within("##{resource_name}_#{resource.id}") do expect(page).to have_css ".label.round" @@ -48,7 +35,6 @@ module Verifications end end - # spec/features/official_positions_spec.rb def expect_no_badge_for(resource_name, resource) within("##{resource_name}_#{resource.id}") do expect(page).not_to have_css ".label.round" @@ -56,12 +42,6 @@ module Verifications end end - # spec/features/tags/budget_investments_spec.rb - # spec/features/tags/proposals_spec.rb - # spec/shared/features/mappable.rb - # spec/shared/features/nested_documentable.rb - # spec/shared/features/nested_imageable.rb - # Used to fill ckeditor fields # @param [String] locator label text for the textarea or textarea id def fill_in_ckeditor(locator, params = {}) # Find out ckeditor id at runtime using its label diff --git a/spec/support/common_actions/votes.rb b/spec/support/common_actions/votes.rb index 21c2e61f5..30cf8bd2e 100644 --- a/spec/support/common_actions/votes.rb +++ b/spec/support/common_actions/votes.rb @@ -1,30 +1,25 @@ module Votes - # spec/features/votes_spec.rb def expect_message_you_need_to_sign_in expect(page).to have_content 'You must Sign in or Sign up to continue' expect(page).to have_selector('.in-favor', visible: false) end - # spec/features/votes_spec.rb def expect_message_you_need_to_sign_in_to_vote_comments expect(page).to have_content 'You must Sign in or Sign up to vote' expect(page).to have_selector('.participation-allowed', visible: false) expect(page).to have_selector('.participation-not-allowed', visible: true) end - # spec/features/votes_spec.rb def expect_message_to_many_anonymous_votes expect(page).to have_content 'Too many anonymous votes to admit vote' expect(page).to have_selector('.in-favor a', visible: false) end - # spec/features/votes_spec.rb def expect_message_only_verified_can_vote_proposals expect(page).to have_content 'Only verified users can vote on proposals' expect(page).to have_selector('.in-favor', visible: false) end - # spec/features/votes_spec.rb def expect_message_voting_not_allowed expect(page).to have_content 'Voting phase is closed' expect(page).not_to have_selector('.in-favor a')