Skip to content

Commit

Permalink
Adiciona gem ao Profile
Browse files Browse the repository at this point in the history
Corrige testes

Co-authored-by: Rosemilson Barbosa <[email protected]>
Co-authored-by: Lucas Vasques <[email protected]>
  • Loading branch information
3 people committed Feb 15, 2024
1 parent a46808c commit bcf0f1e
Show file tree
Hide file tree
Showing 30 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/controllers/connections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ def set_connection_and_profile
end

def set_profile
@profile = Profile.find params[:profile_id]
@profile = Profile.friendly.find params[:profile_id]
end
end
2 changes: 1 addition & 1 deletion app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def redirect_unauthorized_access
end

def set_profile_and_posts
@profile = Profile.find(params[:id])
@profile = Profile.friendly.find(params[:id])
@posts = current_user == @profile.user ? @profile.posts : @profile.posts.published
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def remove_profile
def set_reportable_for_new
reportable_id = params[:reportable]
@reportable = Post.find(reportable_id) if params[:reportable_type] == 'Post'
@reportable = Profile.find(reportable_id) if params[:reportable_type] == 'Profile'
@reportable = Profile.friendly.find(reportable_id) if params[:reportable_type] == 'Profile'
@reportable = Comment.find(reportable_id) if params[:reportable_type] == 'Comment'
@reportable = Reply.find(reportable_id) if params[:reportable_type] == 'Reply'
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def open_to_work
private

def redirect_unauthorized_access
@profile = Profile.find(params[:profile_id])
@profile = Profile.friendly.find(params[:profile_id])
return if current_user == @profile.user

redirect_to root_path, alert: t('alerts.unauthorized')
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/invitations_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class InvitationsMailer < ApplicationMailer
def received_invitation
profile = Profile.find(params[:profile_id])
profile = Profile.friendly.find(params[:profile_id])
project_title = params[:project_title]
mail(subject: t('.subject'), to: profile.user.email,
body: t('.body', title: project_title))
Expand Down
7 changes: 7 additions & 0 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ class Profile < ApplicationRecord
enum privacy: { private_profile: 0, public_profile: 10 }
enum status: { inactive: 0, active: 5 }

extend FriendlyId
friendly_id :profile_permalink, use: :slugged

delegate :full_name, :email, to: :user

def profile_permalink
user.full_name.to_s
end

def self.advanced_search(search_query)
left_outer_joins(:job_categories, :personal_info, :user).where(
'job_categories.name LIKE :term OR
Expand Down
2 changes: 1 addition & 1 deletion spec/system/authentication/visitor_logs_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
click_button class: 'dropdown-toggle'
click_on 'Sair'

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
expect(page).to have_content 'Logout efetuado com sucesso'
end

Expand Down
6 changes: 3 additions & 3 deletions spec/system/connections/user_follows_another_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
expect(mail).to have_received(:deliver_later)

expect(Connection.count).to eq 1
expect(current_path).to eq profile_path(followed)
expect(page).to have_current_path profile_path(followed)
expect(page).to have_content('Agora você está seguindo Eliseu Ramos')
expect(page).not_to have_button('Seguir', exact: true)
expect(page).to have_button('Deixar de Seguir', exact: true)
Expand All @@ -28,7 +28,7 @@

visit profile_path(followed.profile)

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
expect(page).to have_content 'Para continuar, faça login ou registre-se.'
end

Expand All @@ -43,7 +43,7 @@
click_on 'Seguir'

follower_relationship = Connection.last
expect(current_path).to eq profile_path(followed.profile)
expect(page).to have_current_path profile_path(followed.profile)
expect(follower_relationship).to be_active
expect(page).to have_content('Agora você está seguindo Eliseu Ramos')
expect(page).to have_button('Deixar de Seguir', exact: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
click_on 'Deixar de Seguir'

follower_relationship = Connection.last
expect(current_path).to eq profile_path(followed.profile)
expect(page).to have_current_path profile_path(followed.profile)
expect(follower_relationship).to be_inactive
expect(page).to have_content("Você deixou de seguir #{followed.full_name}")
expect(page).to have_button('Seguir', exact: true)
Expand Down
2 changes: 1 addition & 1 deletion spec/system/connections/user_views_followers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

visit profile_following_path(user.profile)

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
end
end
end
2 changes: 1 addition & 1 deletion spec/system/connections/user_views_following_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@

visit profile_connections_path(user.profile)

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
check 'Exibir no Perfil'
click_on 'Salvar'

expect(current_path).to eq new_user_profile_education_info_path
expect(page).to have_current_path new_user_profile_education_info_path
expect(page).to have_content 'Não foi possível cadastrar formação acadêmica'
expect(page).to have_content 'Instituição não pode ficar em branco'
expect(page).to have_content 'Curso não pode ficar em branco'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
check 'Exibir no Perfil'
click_on 'Salvar'

expect(current_path).to eq edit_education_info_path(education_info)
expect(page).to have_current_path edit_education_info_path(education_info)
expect(page).to have_content 'Não foi possível atualizar formação acadêmica'
expect(page).to have_content 'Instituição não pode ficar em branco'
expect(page).to have_content 'Curso não pode ficar em branco'
Expand Down
4 changes: 2 additions & 2 deletions spec/system/invitations/user_views_invitations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
click_on 'Convites'
end

expect(current_path).to eq invitations_path
expect(page).to have_current_path invitations_path
expect(page).to have_content 'Projeto Cola?Bora!'
expect(page).to have_content 'Um projeto muito legal'
expect(page).to have_content "Expira dia: #{I18n.l(invitation.expiration_date, format: :default)}"
Expand Down Expand Up @@ -134,6 +134,6 @@
it 'mas precisa estar logado' do
visit invitations_path

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it 'e deve estar logado' do
visit job_categories_path

expect(current_path).to eq(new_user_session_path)
expect(page).to have_current_path(new_user_session_path)
expect(page).to have_content('Para continuar, faça login ou registre-se.')
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
visit notifications_path
click_on 'Paulo começou a seguir você'

expect(page).to have_current_path profile_path(follower)
expect(page).to have_current_path profile_path(follower.profile.slug)
expect(Notification.last).to be_clicked
end
end
2 changes: 1 addition & 1 deletion spec/system/personal_info/user_edits_personal_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
it 'e é redirecionado para a tela de login' do
visit edit_user_profile_path

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
expect(page).to have_content 'Para continuar, faça login ou registre-se'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/system/posts/user_creates_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
it 'apenas quando autenticado' do
visit new_post_path

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
end

it 'com sucesso' do
Expand Down
10 changes: 5 additions & 5 deletions spec/system/posts/user_edits_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
login_as user
visit edit_post_path(post)

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
expect(page).to have_content 'Você não pode acessar este conteúdo ou realizar esta ação'
end

Expand Down Expand Up @@ -70,7 +70,7 @@
post = create(:post, user:, title: 'Post A', content: 'Primeira postagem')

login_as user
visit profile_path(user)
visit profile_path(user.profile.slug)
within "div#post-#{post.id}" do
click_button id: 'pin'
end
Expand All @@ -91,7 +91,7 @@
post = create(:post, user:, title: 'Post A', content: 'Primeira postagem', pin: 'pinned')

login_as user
visit profile_path(user)
visit profile_path(user.profile.slug)
within 'div#fixed' do
click_button id: 'unpin'
end
Expand All @@ -111,7 +111,7 @@
post2 = create(:post, user:, title: 'Post B', content: 'Segunda postagem')

login_as user
visit profile_path(user)
visit profile_path(user.profile.slug)
within "div#post-#{post.id}" do
click_button id: 'pin'
end
Expand All @@ -134,7 +134,7 @@
other_user = create(:user, citizen_id_number: '61328427056', email: '[email protected]')

login_as other_user
visit profile_path(user)
visit profile_path(user.profile.slug)

expect(page).not_to have_content 'Fixar'
expect(page).not_to have_content 'Desafixar'
Expand Down
6 changes: 3 additions & 3 deletions spec/system/posts/user_views_post_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
click_on 'Pesquisar'
click_on user.full_name

expect(page).to have_current_path(profile_path(user))
expect(page).to have_current_path(profile_path(user.profile.slug))
within 'h2#post-list-title' do
expect(page).to have_content('Publicações')
end
Expand All @@ -39,7 +39,7 @@
published_at: 2.days.from_now)

login_as user
visit profile_path(user)
visit profile_path(user.profile.slug)

expect(page).to have_content 'Há 2 dias'
end
Expand All @@ -56,7 +56,7 @@
create(:post, user:, title: 'Conteúdo C', content: 'Primeira postagem')

login_as user
visit profile_path(user)
visit profile_path(user.profile.slug)

expect(page.body.index('Conteúdo C')).to be < page.body.index('Texto B')
expect(page.body.index('Texto B')).to be < page.body.index('Post A')
Expand Down
2 changes: 1 addition & 1 deletion spec/system/posts/visitor_views_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

visit post_path(post)

expect(current_path).to eq post_path(post)
expect(page).to have_current_path post_path(post)
expect(page).to have_content 'Título do post'
expect(page).to have_content 'Conteúdo do post'
expect(page).to have_link "Criado por #{post.user.full_name}", href: profile_path(post.user.profile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

click_on 'Salvar'

expect(current_path).to eq new_user_profile_professional_info_path
expect(page).to have_current_path new_user_profile_professional_info_path

expect(page).to have_content 'Não foi possível cadastrar experiência profissional'
expect(page).to have_content 'Empresa não pode ficar em branco'
Expand All @@ -67,7 +67,7 @@

click_on 'Salvar'

expect(current_path).to eq new_user_profile_professional_info_path
expect(page).to have_current_path new_user_profile_professional_info_path

expect(page).to have_content 'Não foi possível cadastrar experiência profissional'
expect(page).to have_content 'Empresa não pode ficar em branco'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

click_on 'Salvar'

expect(current_path).to eq edit_professional_info_path(professional_info)
expect(page).to have_current_path edit_professional_info_path(professional_info)

expect(page).to have_content 'Não foi possível atualizar experiência profissional'
expect(page).to have_content 'Empresa não pode ficar em branco'
Expand Down Expand Up @@ -93,7 +93,7 @@

visit edit_professional_info_path(professional_info_user1)

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
expect(page).to have_content 'Não foi possível completar sua ação'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/system/profile/user_views_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
it 'e é redirecionado para a página de login' do
user = create(:user)
visit profile_path(user.profile)
expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
expect(page).to have_content 'Para continuar, faça login ou registre-se'
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
login_as user
visit reports_path

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
expect(page).to have_content 'Você não têm permissão para realizar essa ação.'
end
end
4 changes: 2 additions & 2 deletions spec/system/reports/user_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
login_as user
visit new_report_path params: { reportable: post, reportable_type: post.class.name }

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
expect(page).to have_content 'Essa publicação não está disponível.'
end

Expand Down Expand Up @@ -205,7 +205,7 @@

visit new_report_path params: { reportable: post, reportable_type: post.class.name }

expect(current_path).to eq new_user_session_path
expect(page).to have_current_path new_user_session_path
expect(page).to have_content 'Para continuar, faça login ou registre-se.'
end
end
6 changes: 3 additions & 3 deletions spec/system/searches/user_searches_post_by_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
click_on 'tdd'
end

expect(current_path).to eq searches_path
expect(page).to have_content post.title
expect(page).to have_content another_post.title
expect(page).not_to have_content other_post.title
expect(current_path).to eq searches_path
end

it 'ao buscar por uma hashtag no campo de busca da home' do
Expand All @@ -30,11 +30,11 @@
fill_in 'Buscar', with: '#tdd'
click_on 'Pesquisar'

expect(current_path).to eq searches_path
expect(page).to have_content post.title
expect(page).to have_content another_post.title
expect(page).not_to have_content other_post.title
expect(page).to have_content '2 Publicações com: #tdd'
expect(current_path).to eq searches_path
end

it 'deve ser uma busca exata' do
Expand All @@ -48,10 +48,10 @@
fill_in 'Buscar', with: '#td'
click_on 'Pesquisar'

expect(current_path).to eq searches_path
expect(page).not_to have_content post.title
expect(page).not_to have_content another_post.title
expect(page).not_to have_content other_post.title
expect(page).to have_content 'Nenhum resultado encontrado com: #td'
expect(current_path).to eq searches_path
end
end
2 changes: 1 addition & 1 deletion spec/system/searches/user_searches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
fill_in 'Buscar', with: ''
click_on 'Pesquisar'

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
expect(page).to have_content 'Você precisa informar um termo para fazer a pesquisa'
end
end
Loading

0 comments on commit bcf0f1e

Please sign in to comment.