Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more user info on adoption interest list #109

Merged
merged 5 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/views/ngo_area/adoption_interests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Email Usuário</th>
<th>Nome</th>
<th>Email</th>
<th>Telefone</th>
<th>Pet</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<% @adoption_interests.each do |adoption_interest| %>
<tr>
<td><%=adoption_interest.user.name%></td>
<td><%=adoption_interest.user.email%></td>
<td><%=adoption_interest.user.phone%></td>
<td><a href="<%= edit_ngo_area_pet_path(adoption_interest.pet) %>"><%=adoption_interest.pet.name%></a></td>
<td><%=I18n.l(adoption_interest.created_at, format: :default)%></td>
</tr>
Expand Down
7 changes: 4 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Pet.delete_all
Ngo.delete_all
User.delete_all
AdoptionInterest.delete_all

puts 'Creating NGOs'

Expand All @@ -14,7 +15,7 @@
email: Faker::Internet.email,
site: Faker::Internet.url,
cnpj: CNPJ.generate,
date_start: Faker::Date.backward(1000),
date_start: Faker::Date.backward(days: 1000),
active: true,
city: Faker::Address.city,
state: Faker::Address.state,
Expand All @@ -34,7 +35,7 @@
email: Faker::Internet.email,
site: Faker::Internet.url,
cnpj: CNPJ.generate,
date_start: Faker::Date.backward(1000),
date_start: Faker::Date.backward(days: 1000),
active: true
)

Expand Down Expand Up @@ -68,7 +69,7 @@
pet = Pet.create!(
name: Faker::Name.first_name,
age: Random.rand(10),
description: Faker::Lorem.paragraph_by_chars([100, 50, 200, 300, 500].sample),
description: Faker::Lorem.paragraph_by_chars(number: [100, 50, 200, 300, 500].sample),
sex: ['f', 'm'].sample,
active: true,
ngo_id: ngo_ids.sample
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ def login_user_capybara(trait)
config.before(:each) do |_|
# TO-DO: Configure specs to run on pt-BR as default locale.
I18n.default_locale = :en
stub_const('ApplicationController::DEFAULT_LOCALE', 'en')
stub_const("#{ApplicationController}::DEFAULT_LOCALE", 'en')
end
end
54 changes: 54 additions & 0 deletions spec/views/ngo_area/adoption_interests/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'rails_helper'

describe 'adoption_interests/index.html.erb', type: :feature do
describe 'permissions' do
let!(:ngo_1) { create(:ngo) }
let!(:ngo_2) { create(:ngo) }
let!(:pet_1) { create(:pet, ngo: ngo_1) }
let!(:pet_2) { create(:pet, ngo: ngo_2) }
let!(:public_user_1) { create(:user) }
let!(:public_user_2) { create(:user) }
let!(:adoption_interest_1) { create(:adoption_interest, user: public_user_1, pet: pet_1) }
let!(:adoption_interest_2) { create(:adoption_interest, user: public_user_2, pet: pet_2) }

context 'when user has ngo privileges' do
let!(:current_user) do
ngo_user = create(:user, :ngo_privileges)
ngo_user.ngos << ngo_1

ngo_user
end

before do
login_as(current_user, scope: :user)
end

it 'shows adoption requests from ngo 1 pets' do
visit ngo_area_adoption_interests_path

expect(page).to have_link(nil, href: edit_ngo_area_pet_path(pet_1))
end

it 'does not show adoption requests from ngo 2 pets' do
visit ngo_area_adoption_interests_path

expect(page).not_to have_link(nil, href: edit_ngo_area_pet_path(pet_2))
end
end

context 'when user has admin privileges' do
let!(:current_user) { create(:user, :admin_privileges) }

before do
login_as(current_user, scope: :user)
end

it 'shows show adoption from all ngos' do
visit ngo_area_adoption_interests_path

expect(page).to have_link(nil, href: edit_ngo_area_pet_path(pet_1))
expect(page).to have_link(nil, href: edit_ngo_area_pet_path(pet_2))
end
end
end
end