This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| RSpec.describe Admin::ResidencesController do | |
| let(:user) { build_stubbed(:user) } | |
| let(:residence) { build_stubbed(:residence, id: 1) } | |
| context "#valid_user" do | |
| let(:setup) { | |
| allow(Residence).to receive(:find).with(residence.id.to_s) | |
| .and_return(residence) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| RSpec.describe Admin::ResidencesController do | |
| let(:setup) {} | |
| let(:user) { double('user') } | |
| let(:valid_params) { attributes_for(:residence, cep: "57000-000") } | |
| let(:residence_101) { build_stubbed(:residence) } | |
| context "Valid User" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.shared_examples "redirectable action" do |route_name| | |
| it "redirects to #{route_name}" do | |
| expect(response).to redirect_to(path) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.shared_examples "renderable action" do |template_to_render| | |
| it "renders #{template_to_render} template" do | |
| expect(response).to render_template(template_to_render) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.shared_context 'redirect to sign in' do | |
| describe "user not logged in" do | |
| before { | |
| before_action | |
| } | |
| it "redirects to sign_in" do | |
| expect(response).to redirect_to(new_user_session_path) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| RSpec.describe 'Residence Integration Tests' do | |
| let(:user) { create(:user, email: 'admin@admin.com', password: '123456') } | |
| let(:login_page) { LoginPageObject.new } | |
| let(:index_page) { IndexResidencePage.new } | |
| context '#valid_user' do | |
| before { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LoginPageObject < BaseObject | |
| def visit_root | |
| visit '/' | |
| self | |
| end | |
| def login(user) | |
| fill_in I18n.t('activerecord.attributes.user.email'), with: user.email | |
| fill_in I18n.t('activerecord.attributes.user.password'), with: user.password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class IndexResidencePage < BaseObject | |
| def visit_page | |
| visit admin_residences_path | |
| self | |
| end | |
| def has_residence?(residence) | |
| content = find(:xpath, '//table/tbody/tr') | |
| has_expected_fields_in_table(content, residence) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NewResidencePageObject < BaseObject | |
| def has_current_path?(path) | |
| current_path == path | |
| end | |
| def fill_in_with_residence(residence) | |
| find("#residence_latitude").set(residence.latitude) | |
| find("#residence_longitude").set(residence.longitude) | |
| fill_in I18n.t('activerecord.attributes.residence.type_of_patio'), with: residence.type_of_patio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EditResidencePageObject < BaseObject | |
| def change_field(id, value) | |
| find(id).set(value) | |
| end | |
| def click_on_save | |
| click_on 'Atualizar' | |
| IndexResidencePage.new | |
| end |