Skip to content

Instantly share code, notes, and snippets.

View thiagoramos23's full-sized avatar

Thiago Ramos thiagoramos23

View GitHub Profile
@thiagoramos23
thiagoramos23 / show_residence_spec.rb
Created October 23, 2014 10:06
Show Residence Spec
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)
@thiagoramos23
thiagoramos23 / update_residence_spec.rb
Created October 23, 2014 10:06
Update Residence Spec
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
@thiagoramos23
thiagoramos23 / redirectable_action.rb
Created October 23, 2014 10:20
Redirectable Action
RSpec.shared_examples "redirectable action" do |route_name|
it "redirects to #{route_name}" do
expect(response).to redirect_to(path)
end
end
@thiagoramos23
thiagoramos23 / renderable_action.rb
Created October 23, 2014 10:20
Renderable Action
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
@thiagoramos23
thiagoramos23 / redirect_to_sign_in.rb
Created October 23, 2014 10:21
Redirect To Sign In
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
@thiagoramos23
thiagoramos23 / residence_acceptance_spec.rb
Created November 8, 2014 03:43
residence_acceptance_spec
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 {
@thiagoramos23
thiagoramos23 / login_page_object.rb
Created November 8, 2014 03:44
login_page_object
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
@thiagoramos23
thiagoramos23 / index_residence_page_object.rb
Created November 8, 2014 03:45
index_residence_page_object
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)
@thiagoramos23
thiagoramos23 / new_residence_page_object.rb
Last active August 29, 2015 14:08
new_residence_page_object
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
@thiagoramos23
thiagoramos23 / edit_residence_page_object.rb
Created November 11, 2014 17:48
edit_residence_page_object
class EditResidencePageObject < BaseObject
def change_field(id, value)
find(id).set(value)
end
def click_on_save
click_on 'Atualizar'
IndexResidencePage.new
end