diff --git a/Gemfile b/Gemfile index 2ae20f8..e1c00d5 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'devise' gem 'faker' gem 'faraday' +gem 'friendly_id', '~> 5.5.0' gem 'image_processing', '>= 1.2' gem 'jbuilder' gem 'jsbundling-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 3de4bb0..c4cb9c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,6 +136,8 @@ GEM webrick (~> 1.7) websocket-driver (>= 0.6, < 0.8) ffi (1.16.3) + friendly_id (5.5.1) + activerecord (>= 4.0.0) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) @@ -339,6 +341,7 @@ DEPENDENCIES factory_bot_rails faker faraday + friendly_id (~> 5.5.0) image_processing (>= 1.2) jbuilder jsbundling-rails diff --git a/README.md b/README.md index 589a7c6..b7c5d91 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ O Portfoliorrr é uma rede social com funcionalidades de portfólio para pessoas - Rode o comando `bin/setup` e aguarde sua conclusão; - Rode o comando `yarn install` (necessário ter `node` instalado em sua máquina); +## Populando o banco de dados + +- O seed comum, para desenvolvimento, pode ser feito normalmente com `rails db:seed` +- Para apresentações e testes de front-end, é possível fazer um superseed, utilizando `rails db:seed:superseed` +- O superseed utiliza as gems Faker e FactoryBot, que são instaladas durante a configuração (ver item anterior) + ## Como visualizar a aplicação no navegador - Siga as instruções de configuração da aplicação diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index 0753494..258a979 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -3,10 +3,10 @@ module V1 class ProfilesController < ApiController def index if params[:search].blank? - profiles = Profile.active.open_to_work + profiles = Profile.active.open_to_work.order_by_premium profiles = profiles.map { |profile| format_profile(profile) } else - profiles = Profile.active.open_to_work.get_profile_job_categories_json(params[:search]) + profiles = Profile.active.open_to_work.order_by_premium.get_profile_job_categories_json(params[:search]) end render status: :ok, json: { data: profiles } end diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 44685ba..78d3064 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -2,7 +2,7 @@ module Api module V1 class ProjectsController < ApiController def index - response = Faraday.get('http://localhost:3000/api/v1/projects') + response = ProjectsService::ColaBoraApiGetProjects.send if response.status == 200 projects = JSON.parse(response.body) render status: :ok, json: projects.as_json @@ -13,9 +13,9 @@ def index end def request_invitation - data = proposal_params.as_json - connection = Faraday.new(url: 'http://localhost:3000', params: data) - response = connection.post('api/v1/proposals') + invitation_request_id = proposal_params.fetch('invitation_request_id').to_i + invitation_request = InvitationRequest.find(invitation_request_id) + response = InvitationRequestService::ColaBoraInvitationRequestPost.send(invitation_request) if response.status == 201 proposal = JSON.parse(response.body) @@ -29,8 +29,7 @@ def request_invitation private def proposal_params - proposal_attributes = %i[invitation_request_id email message profile_id project_id] - params.require(:data).permit(proposal: proposal_attributes) + params.permit(:invitation_request_id) end end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 95f998c..180c22e 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,15 +1,21 @@ class CommentsController < ApplicationController before_action :authenticate_user! + before_action :set_post def create - post = Post.find(params[:post_id]) comments_params = params.require(:comment).permit(:message) comments_params[:user_id] = current_user.id - comment = post.comments.build(comments_params) + comment = @post.comments.build(comments_params) if comment.save - redirect_to post, notice: t('.success') + redirect_to @post, notice: t('.success') else - redirect_to post, alert: t('.error') + redirect_to @post, alert: t('.error') end end end + +private + +def set_post + @post = Post.friendly.find(params[:post_id]) +end diff --git a/app/controllers/connections_controller.rb b/app/controllers/connections_controller.rb index 94979c4..62b4796 100644 --- a/app/controllers/connections_controller.rb +++ b/app/controllers/connections_controller.rb @@ -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 diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 6029ca5..fec2e33 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -25,7 +25,7 @@ def show; end private def set_invitation - @invitation = Invitation.find(params[:id]) + @invitation = Invitation.friendly.find(params[:id]) end def authorize! diff --git a/app/controllers/posts/likes_controller.rb b/app/controllers/posts/likes_controller.rb index b0024a0..7175121 100644 --- a/app/controllers/posts/likes_controller.rb +++ b/app/controllers/posts/likes_controller.rb @@ -5,7 +5,7 @@ class LikesController < LikesController private def set_likeable - @likeable = Post.find(params[:post_id]) + @likeable = Post.friendly.find(params[:post_id]) @post = @likeable end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 7adfc0c..69df32f 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -68,7 +68,7 @@ def post_params end def set_post - @post = Post.find(params[:id]) + @post = Post.friendly.find(params[:id]) end def authorize! diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index cb98688..3ae500c 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 73ba19a..8951cd0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -6,6 +6,7 @@ def index @invitation_request = current_user.invitation_requests.build @invitation_requests = current_user.invitation_requests.pluck(:project_id).to_json @invitation_requests_projects_ids = current_user.invitation_requests.pluck(:project_id) + @projects_url = Rails.configuration.portfoliorrr_api_v1.projects_url @free_user = current_user.subscription.inactive? end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 1407fce..ea5b8d2 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -48,10 +48,11 @@ 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 = Comment.find(reportable_id) if params[:reportable_type] == 'Comment' - @reportable = Reply.find(reportable_id) if params[:reportable_type] == 'Reply' + reportable_type = params[:reportable_type] + @reportable = Post.friendly.find(reportable_id) if reportable_type == 'Post' + @reportable = Profile.friendly.find(reportable_id) if reportable_type == 'Profile' + @reportable = Comment.find(reportable_id) if reportable_type == 'Comment' + @reportable = Reply.find(reportable_id) if reportable_type == 'Reply' end def set_reportable_for_create diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index fde87ca..d7675e7 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -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') diff --git a/app/javascript/components/projects_vue.js b/app/javascript/components/projects_vue.js index 142c59c..53b7be4 100644 --- a/app/javascript/components/projects_vue.js +++ b/app/javascript/components/projects_vue.js @@ -12,6 +12,7 @@ export default { invitationRequestsProjectsIds: window.invitationRequestsProjectsIds, freeUser: window.freeUser, errorMsg: false, + portfoliorrrProjectsApiUrl: window.portfoliorrrProjectsApiUrl, } }, computed:{ @@ -47,7 +48,7 @@ export default { async created() { if (!freeUser) { try { - let response = await fetch('/api/v1/projects', { signal }); + let response = await fetch(this.portfoliorrrProjectsApiUrl, { signal }); if (response.ok) { let data = await response.json(); if (!data.message) { diff --git a/app/jobs/decline_invitation_job.rb b/app/jobs/decline_invitation_job.rb index 85d2149..7588ff9 100644 --- a/app/jobs/decline_invitation_job.rb +++ b/app/jobs/decline_invitation_job.rb @@ -1,10 +1,12 @@ class DeclineInvitationJob < ApplicationJob + PORTFOLIORRR_BASE_URL = Rails.configuration.portfoliorrr_api_v1.base_url + PORTFOLIORRR_INVITATION_URL = Rails.configuration.portfoliorrr_api_v1.invitations_url retry_on Faraday::ConnectionFailed, Faraday::ServerError, wait: :polynomially_longer, attempts: 5 do |job| job.arguments.first.pending! end def perform(invitation) - url = "http://localhost:4000/api/v1/invitations/#{invitation.colabora_invitation_id}" + url = "#{PORTFOLIORRR_BASE_URL}#{PORTFOLIORRR_INVITATION_URL}#{invitation.colabora_invitation_id}" Faraday.new { |faraday| faraday.response :raise_error }.patch(url) invitation.declined! rescue Faraday::ResourceNotFound, Faraday::ConflictError diff --git a/app/jobs/request_invitation_job.rb b/app/jobs/request_invitation_job.rb index 23b5659..2805113 100644 --- a/app/jobs/request_invitation_job.rb +++ b/app/jobs/request_invitation_job.rb @@ -1,4 +1,6 @@ class RequestInvitationJob < ApplicationJob + PORTFOLIORRR_BASE_URL = Rails.configuration.portfoliorrr_api_v1.base_url + PORTFOLIORRRR_REQUEST_INVITATION_URL = Rails.configuration.portfoliorrr_api_v1.request_invitation_url queue_as :default retry_on Exceptions::PortfoliorrrAPIOffline, wait: 1.hour, attempts: :unlimited retry_on Exceptions::ColaBoraAPIOffline, wait: 1.hour, attempts: 5 do |job, _error| @@ -6,8 +8,8 @@ class RequestInvitationJob < ApplicationJob end def perform(invitation_request:) - data = invitation_request.create_json_for_proposal_request - response = Faraday.new(url: 'http://localhost:4000', params: data).get('/api/v1/projects/request_invitation') + data = { invitation_request_id: invitation_request.id }.as_json + response = Faraday.new(url: PORTFOLIORRR_BASE_URL, params: data).get(PORTFOLIORRRR_REQUEST_INVITATION_URL) return raise Exceptions::PortfoliorrrAPIOffline if response.status == :internal_server_error invitation_request.process_colabora_api_response(response) diff --git a/app/mailers/invitations_mailer.rb b/app/mailers/invitations_mailer.rb index 1e1e480..21de21e 100644 --- a/app/mailers/invitations_mailer.rb +++ b/app/mailers/invitations_mailer.rb @@ -1,8 +1,7 @@ class InvitationsMailer < ApplicationMailer def received_invitation - profile = Profile.find(params[:profile_id]) - project_title = params[:project_title] - mail(subject: t('.subject'), to: profile.user.email, - body: t('.body', title: project_title)) + @profile = Profile.friendly.find(params[:profile_id]) + @project_title = params[:project_title] + mail(subject: t('.subject'), to: @profile.user.email) end end diff --git a/app/models/invitation.rb b/app/models/invitation.rb index b5a492c..7cf0a4d 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -13,6 +13,9 @@ class Invitation < ApplicationRecord after_create :create_notification after_create :validate_and_approve_pending_request + extend FriendlyId + friendly_id :project_title, use: :slugged + def set_status self.status = 'pending' end diff --git a/app/models/invitation_request.rb b/app/models/invitation_request.rb index ac2723f..2edd0af 100644 --- a/app/models/invitation_request.rb +++ b/app/models/invitation_request.rb @@ -22,14 +22,6 @@ def process_colabora_api_response(response) end end - def create_json_for_proposal_request - { data: { proposal: { invitation_request_id: id, - project_id:, - profile_id: profile.id, - email: profile.email, - message: } } }.as_json - end - private def json_treated_response(response) diff --git a/app/models/post.rb b/app/models/post.rb index 51134ac..a3ea31c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -20,6 +20,9 @@ class Post < ApplicationRecord has_rich_text :content + extend FriendlyId + friendly_id :title, use: :slugged + def self.get_sample(amount) published.sample amount end diff --git a/app/models/profile.rb b/app/models/profile.rb index 663de5e..ce155f7 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,30 +1,22 @@ class Profile < ApplicationRecord belongs_to :user + has_one_attached :photo has_one :personal_info, dependent: :destroy has_many :professional_infos, dependent: :destroy has_many :education_infos, dependent: :destroy has_many :profile_job_categories, dependent: :destroy - - has_many :followers, class_name: 'Connection', foreign_key: :followed_profile_id, dependent: :destroy, - inverse_of: :follower - - has_many :followed_profiles, class_name: 'Connection', foreign_key: :follower_id, - dependent: :destroy, inverse_of: :followed_profile - - has_many :connections, foreign_key: :followed_profile_id, dependent: :destroy, inverse_of: :followed_profile - - has_many :job_categories, through: :profile_job_categories - has_many :invitation_requests, dependent: :destroy - - has_one_attached :photo has_many :invitations, dependent: :destroy - has_many :posts, through: :user has_many :notifications, dependent: :destroy - + has_many :invitation_requests, dependent: :destroy + has_many :posts, through: :user + has_many :job_categories, through: :profile_job_categories has_many :reports_submitted, class_name: 'Report', dependent: :destroy - has_many :reports_received, class_name: 'Report', as: :reportable, dependent: :destroy - + has_many :connections, foreign_key: :followed_profile_id, dependent: :destroy, inverse_of: :followed_profile + has_many :followers, class_name: 'Connection', foreign_key: :followed_profile_id, dependent: :destroy, + inverse_of: :follower + has_many :followed_profiles, class_name: 'Connection', foreign_key: :follower_id, dependent: :destroy, + inverse_of: :followed_profile accepts_nested_attributes_for :personal_info accepts_nested_attributes_for :professional_infos accepts_nested_attributes_for :education_infos @@ -38,24 +30,33 @@ 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.order_by_premium + joins(user: :subscription).order('subscriptions.status DESC, users.full_name ASC') + end + def self.advanced_search(search_query) left_outer_joins(:job_categories, :personal_info, :user).where( - 'job_categories.name LIKE :term OR - personal_infos.city LIKE :term OR - users.full_name LIKE :term OR users.search_name LIKE :term', + 'job_categories.name LIKE :term OR personal_infos.city LIKE :term OR users.full_name LIKE :term + OR users.search_name LIKE :term', { term: "%#{sanitize_sql_like(search_query)}%" } ).public_profile.active.uniq end def self.get_profile_job_categories_json(query) profiles = search_by_job_categories(query) - profiles_json = profiles.map do |profile| + profiles.map do |profile| { user_id: profile.user_id, full_name: profile.full_name, job_categories: ProfileJobCategory.generate_profile_job_categories_json(profile.id) } - end - profiles_json.as_json + end.as_json end def self.search_by_job_categories(query) @@ -92,10 +93,7 @@ def self.most_followed(limit) def inactive! super user.update(old_name: user.full_name, full_name: 'Perfil Desativado') - user.posts.each do |post| - post.update(old_status: post.status) - end - + user.posts.each { |post| post.update(old_status: post.status) } user.posts.each(&:archived!) Connection.where(follower: self).or(Connection.where(followed_profile: self)).find_each(&:inactive!) end @@ -103,9 +101,7 @@ def inactive! def active! super user.update(full_name: user.old_name) - user.posts.each do |post| - post.update(status: post.old_status) - end + user.posts.each { |post| post.update(status: post.old_status) } Connection.where(follower: self).or(Connection.where(followed_profile: self)).find_each(&:active!) end diff --git a/app/services/invitation_request_service.rb b/app/services/invitation_request_service.rb index 85a38c5..7822f0e 100644 --- a/app/services/invitation_request_service.rb +++ b/app/services/invitation_request_service.rb @@ -1,35 +1,15 @@ module InvitationRequestService - COLABORA_PROJECTS_URL = 'http://localhost:3000/api/v1/projects'.freeze - COLABORA_INVITATIONS_BASE_URL = 'http://localhost:3000/api/v1/invitations'.freeze + include ProjectsService - class ColaboraProject - def self.send - @response = Faraday.get(COLABORA_PROJECTS_URL) - return build_projects if @response.success? - - raise StandardError - end - - class << self - private - - def build_projects - projects = JSON.parse(@response.body, symbolize_names: true) - projects.map do |project| - Project.new(id: project[:id], - title: project[:title], - description: project[:description], - category: project[:category]) - end - end - end - end + COLABORA_BASE_URL = Rails.configuration.colabora_api_v1.base_url + COLABORA_API_V1_PROJECTS_URL = Rails.configuration.colabora_api_v1.projects_url + COLABORA_API_V1_PROPOSALS_URL = Rails.configuration.colabora_api_v1.proposals_url class InvitationRequest def self.send(requests) return [] if requests.empty? - projects = ColaboraProject.send + projects = ProjectsService::ColaBoraProject.send requests.map do |request| project = projects.find { |proj| proj.id == request.project_id } @@ -37,4 +17,28 @@ def self.send(requests) end end end + + class ColaBoraInvitationRequestPost + def self.send(invitation_request) + @invitation_request = invitation_request + post_connection + + @response + end + + class << self + private + + def build_invitation_request_params(invitation_request) + { 'proposal': { 'invitation_request_id': invitation_request.id, 'email': invitation_request.profile.email, + 'message': invitation_request.message, 'profile_id': invitation_request.profile.id, + 'project_id': invitation_request.project_id } }.as_json + end + + def post_connection + url = "#{COLABORA_BASE_URL}#{COLABORA_API_V1_PROPOSALS_URL}" + @response = Faraday.post(url, build_invitation_request_params(@invitation_request)) + end + end + end end diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb new file mode 100644 index 0000000..449f2d6 --- /dev/null +++ b/app/services/projects_service.rb @@ -0,0 +1,34 @@ +module ProjectsService + COLABORA_BASE_URL = Rails.configuration.colabora_api_v1.base_url + COLABORA_API_V1_PROJECTS_URL = Rails.configuration.colabora_api_v1.projects_url + + class ColaBoraProject + def self.send + @response = ColaBoraApiGetProjects.send + return build_projects if @response.success? + + raise StandardError + end + + class << self + private + + def build_projects + projects = JSON.parse(@response.body, symbolize_names: true) + projects.map do |project| + Project.new(id: project[:id], + title: project[:title], + description: project[:description], + category: project[:category]) + end + end + end + end + + class ColaBoraApiGetProjects + def self.send + url = "#{COLABORA_BASE_URL}#{COLABORA_API_V1_PROJECTS_URL}" + Faraday.get(url) + end + end +end diff --git a/app/views/connections_mailer/notify_follow.html.erb b/app/views/connections_mailer/notify_follow.html.erb index 6620377..766b5c5 100644 --- a/app/views/connections_mailer/notify_follow.html.erb +++ b/app/views/connections_mailer/notify_follow.html.erb @@ -1 +1,7 @@ -

<%= @notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %>

+

<%= t('.greeting', recipient: @notification.profile.full_name) %>

+ +

<%= link_to @notification.notifiable.follower.full_name, profile_url(@notification.notifiable.follower) %> <%= t('notifications.started_following_you') %>

+ +

<%= link_to t('click_btn'), @notification.profile %> <%= t('.access_profile') %>

+<%= t('.regards') %> +

Portfoliorrr

\ No newline at end of file diff --git a/app/views/invitations/show.html.erb b/app/views/invitations/show.html.erb index d3d18be..705aa6c 100644 --- a/app/views/invitations/show.html.erb +++ b/app/views/invitations/show.html.erb @@ -16,7 +16,7 @@ <% if @invitation.pending? %>
- <%= link_to t('accept_btn'), 'http://localhost:3000', class: 'btn btn-primary me-4' %> + <%= link_to t('accept_btn'), Rails.configuration.colabora_api_v1.base_url, class: 'btn btn-primary me-4' %>
<%= button_to t('decline_btn'), decline_invitation_path(@invitation), method: :patch, class: 'btn btn-secondary' %> diff --git a/app/views/invitations_mailer/received_invitation.html.erb b/app/views/invitations_mailer/received_invitation.html.erb new file mode 100644 index 0000000..0a1d558 --- /dev/null +++ b/app/views/invitations_mailer/received_invitation.html.erb @@ -0,0 +1,7 @@ +

<%= t('.greeting', recipient: @profile.full_name) %>

+ +

<%= t('.body', title: @project_title) %>

+ +

<%= link_to t('click_btn'), invitations_url %> <%= t('.access_invitations') %>

+<%= t('.regards') %> +

Portfoliorrr

\ No newline at end of file diff --git a/app/views/likes_mailer/notify_like.html.erb b/app/views/likes_mailer/notify_like.html.erb index 9195aa9..e59dbbb 100644 --- a/app/views/likes_mailer/notify_like.html.erb +++ b/app/views/likes_mailer/notify_like.html.erb @@ -6,12 +6,12 @@
<%= t('.comment_likes', like_count: @comment_likes.count) if @comment_likes.any? %>
<% if @post_likes.any? %> -

<%= t('.most_liked_post') %> <%= link_to @most_liked_post.title, post_url(@most_liked_post) %>

+

<%= t('.most_liked_post') %> <%= link_to @most_liked_post.title, post_url(@most_liked_post) %>

<% end %> <% if @comment_likes.any? %>

<%= t('.most_liked_comment', comment: @most_liked_comment.message) %> <%= link_to @most_liked_comment.post.title, post_url(@most_liked_comment.post) %>

<% end %> -

<%= link_to t('click_btn'), profile_url(@user.profile) %> <%= t('.access_profile') %>

+

<%= link_to t('click_btn'), profile_url(@user.profile) %> <%= t('.access_profile') %>

<%= t('.regards') %>, -Portfoliorrr \ No newline at end of file +

Portfoliorrr

\ No newline at end of file diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 60ccb79..b1c03b0 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -44,9 +44,11 @@

<% end %>

- + <% if @post.edited_at.present? %> + + <% end %>

diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index b35c450..9200042 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -74,6 +74,7 @@

diff --git a/app/views/reports/_post.html.erb b/app/views/reports/_post.html.erb index 7718a6d..9383253 100644 --- a/app/views/reports/_post.html.erb +++ b/app/views/reports/_post.html.erb @@ -7,16 +7,26 @@

<%= post.content %>

-

- -

-

- -

+ <% if post.published_at.present? %> +

+ +

+ <% else %> +

+ +

+ <% end %> + <% if post.edited_at.present? %> +

+ +

+ <% end %>

<% post.tags.each do |tag| %> diff --git a/config/application.rb b/config/application.rb index ff33ae3..b2e37ee 100644 --- a/config/application.rb +++ b/config/application.rb @@ -38,5 +38,11 @@ class Application < Rails::Application # Don't generate system test files. config.generators.system_tests = nil + + # ColaBora API configurations + config.colabora_api_v1 = config_for(:colabora_api_v1) + + # Portfoliorrr API configurations + config.portfoliorrr_api_v1 = config_for(:portfoliorrr_api_v1) end end diff --git a/config/colabora_api_v1.yml b/config/colabora_api_v1.yml new file mode 100644 index 0000000..9168649 --- /dev/null +++ b/config/colabora_api_v1.yml @@ -0,0 +1,9 @@ +development: + base_url: 'http://localhost:3000' + projects_url: '/api/v1/projects' + proposals_url: '/api/v1/proposals' + +test: + base_url: 'http://localhost:3000' + projects_url: '/api/v1/projects' + proposals_url: '/api/v1/proposals' \ No newline at end of file diff --git a/config/initializers/friendly_id.rb b/config/initializers/friendly_id.rb new file mode 100644 index 0000000..5852b58 --- /dev/null +++ b/config/initializers/friendly_id.rb @@ -0,0 +1,107 @@ +# FriendlyId Global Configuration +# +# Use this to set up shared configuration options for your entire application. +# Any of the configuration options shown here can also be applied to single +# models by passing arguments to the `friendly_id` class method or defining +# methods in your model. +# +# To learn more, check out the guide: +# +# http://norman.github.io/friendly_id/file.Guide.html + +FriendlyId.defaults do |config| + # ## Reserved Words + # + # Some words could conflict with Rails's routes when used as slugs, or are + # undesirable to allow as slugs. Edit this list as needed for your app. + config.use :reserved + + config.reserved_words = %w[new edit index session login logout users admin + stylesheets assets javascripts images] + + # This adds an option to treat reserved words as conflicts rather than exceptions. + # When there is no good candidate, a UUID will be appended, matching the existing + # conflict behavior. + + # config.treat_reserved_as_conflict = true + + # ## Friendly Finders + # + # Uncomment this to use friendly finders in all models. By default, if + # you wish to find a record by its friendly id, you must do: + # + # MyModel.friendly.find('foo') + # + # If you uncomment this, you can do: + # + # MyModel.find('foo') + # + # This is significantly more convenient but may not be appropriate for + # all applications, so you must explicitly opt-in to this behavior. You can + # always also configure it on a per-model basis if you prefer. + # + # Something else to consider is that using the :finders addon boosts + # performance because it will avoid Rails-internal code that makes runtime + # calls to `Module.extend`. + # + # config.use :finders + # + # ## Slugs + # + # Most applications will use the :slugged module everywhere. If you wish + # to do so, uncomment the following line. + # + # config.use :slugged + # + # By default, FriendlyId's :slugged addon expects the slug column to be named + # 'slug', but you can change it if you wish. + # + # config.slug_column = 'slug' + # + # By default, slug has no size limit, but you can change it if you wish. + # + # config.slug_limit = 255 + # + # When FriendlyId can not generate a unique ID from your base method, it appends + # a UUID, separated by a single dash. You can configure the character used as the + # separator. If you're upgrading from FriendlyId 4, you may wish to replace this + # with two dashes. + # + # config.sequence_separator = '-' + # + # Note that you must use the :slugged addon **prior** to the line which + # configures the sequence separator, or else FriendlyId will raise an undefined + # method error. + # + # ## Tips and Tricks + # + # ### Controlling when slugs are generated + # + # As of FriendlyId 5.0, new slugs are generated only when the slug field is + # nil, but if you're using a column as your base method can change this + # behavior by overriding the `should_generate_new_friendly_id?` method that + # FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave + # more like 4.0. + # Note: Use(include) Slugged module in the config if using the anonymous module. + # If you have `friendly_id :name, use: slugged` in the model, Slugged module + # is included after the anonymous module defined in the initializer, so it + # overrides the `should_generate_new_friendly_id?` method from the anonymous module. + # + # config.use :slugged + # config.use Module.new { + # def should_generate_new_friendly_id? + # slug.blank? || _changed? + # end + # } + # + # FriendlyId uses Rails's `parameterize` method to generate slugs, but for + # languages that don't use the Roman alphabet, that's not usually sufficient. + # Here we use the Babosa library to transliterate Russian Cyrillic slugs to + # ASCII. If you use this, don't forget to add "babosa" to your Gemfile. + # + # config.use Module.new { + # def normalize_friendly_id(text) + # text.to_slug.normalize! :transliterations => [:russian, :latin] + # end + # } +end diff --git a/config/locales/models/connections.pt-BR.yml b/config/locales/models/connections.pt-BR.yml index a8d1387..07cd5f6 100644 --- a/config/locales/models/connections.pt-BR.yml +++ b/config/locales/models/connections.pt-BR.yml @@ -29,4 +29,7 @@ pt-BR: connections_mailer: notify_follow: - subject: 'Alguém seguiu seu perfil' \ No newline at end of file + subject: 'Alguém seguiu seu perfil' + greeting: Olá, %{recipient}! + access_profile: para acessar seu perfil e continuar interagindo. + regards: Abraços, \ No newline at end of file diff --git a/config/locales/models/invitation.pt-BR.yml b/config/locales/models/invitation.pt-BR.yml index 019e826..c17d43b 100644 --- a/config/locales/models/invitation.pt-BR.yml +++ b/config/locales/models/invitation.pt-BR.yml @@ -32,5 +32,8 @@ pt-BR: invitations_mailer: received_invitation: + greeting: Olá, %{recipient}! subject: 'Você recebeu um convite' - body: Você recebeu um convite para participar do projeto %{title}. + body: Você recebeu um convite para participar do projeto %{title}. + access_invitations: para ver seus convites e aceitá-los. + regards: Abraços, diff --git a/config/portfoliorrr_api_v1.yml b/config/portfoliorrr_api_v1.yml new file mode 100644 index 0000000..75c9712 --- /dev/null +++ b/config/portfoliorrr_api_v1.yml @@ -0,0 +1,11 @@ +development: + base_url: 'http://localhost:4000' + invitations_url: '/api/v1/invitations/' + request_invitation_url: '/api/v1/projects/request_invitation' + projects_url: '/api/v1/projects' + +test: + base_url: 'http://localhost:4000' + invitations_url: '/api/v1/invitations/' + request_invitation_url: '/api/v1/projects/request_invitation' + projects_url: '/api/v1/projects' diff --git a/db/migrate/20240215115659_add_slug_to_profiles.rb b/db/migrate/20240215115659_add_slug_to_profiles.rb new file mode 100644 index 0000000..e8983ab --- /dev/null +++ b/db/migrate/20240215115659_add_slug_to_profiles.rb @@ -0,0 +1,6 @@ +class AddSlugToProfiles < ActiveRecord::Migration[7.1] + def change + add_column :profiles, :slug, :string + add_index :profiles, :slug, unique: true + end +end diff --git a/db/migrate/20240215171014_add_slug_to_posts.rb b/db/migrate/20240215171014_add_slug_to_posts.rb new file mode 100644 index 0000000..8b0745c --- /dev/null +++ b/db/migrate/20240215171014_add_slug_to_posts.rb @@ -0,0 +1,6 @@ +class AddSlugToPosts < ActiveRecord::Migration[7.1] + def change + add_column :posts, :slug, :string + add_index :posts, :slug, unique: true + end +end diff --git a/db/migrate/20240215173337_add_slug_to_invitations.rb b/db/migrate/20240215173337_add_slug_to_invitations.rb new file mode 100644 index 0000000..ee67bf3 --- /dev/null +++ b/db/migrate/20240215173337_add_slug_to_invitations.rb @@ -0,0 +1,6 @@ +class AddSlugToInvitations < ActiveRecord::Migration[7.1] + def change + add_column :invitations, :slug, :string + add_index :invitations, :slug, unique: true + end +end diff --git a/db/migrate/20240215181135_create_friendly_id_slugs.rb b/db/migrate/20240215181135_create_friendly_id_slugs.rb new file mode 100644 index 0000000..a09491d --- /dev/null +++ b/db/migrate/20240215181135_create_friendly_id_slugs.rb @@ -0,0 +1,21 @@ +MIGRATION_CLASS = + if ActiveRecord::VERSION::MAJOR >= 5 + ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"] + else + ActiveRecord::Migration + end + +class CreateFriendlyIdSlugs < MIGRATION_CLASS + def change + create_table :friendly_id_slugs do |t| + t.string :slug, null: false + t.integer :sluggable_id, null: false + t.string :sluggable_type, limit: 50 + t.string :scope + t.datetime :created_at + end + add_index :friendly_id_slugs, [:sluggable_type, :sluggable_id] + add_index :friendly_id_slugs, [:slug, :sluggable_type], length: {slug: 140, sluggable_type: 50} + add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], length: {slug: 70, sluggable_type: 50, scope: 70}, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 1e32535..5aa8144 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_14_151256) do +ActiveRecord::Schema[7.1].define(version: 2024_02_15_181135) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -84,6 +84,17 @@ t.index ["profile_id"], name: "index_education_infos_on_profile_id" end + create_table "friendly_id_slugs", force: :cascade do |t| + t.string "slug", null: false + t.integer "sluggable_id", null: false + t.string "sluggable_type", limit: 50 + t.string "scope" + t.datetime "created_at" + t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true + t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type" + t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id" + end + create_table "invitation_requests", force: :cascade do |t| t.integer "profile_id", null: false t.text "message" @@ -108,7 +119,9 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "project_id", null: false + t.string "slug" t.index ["profile_id"], name: "index_invitations_on_profile_id" + t.index ["slug"], name: "index_invitations_on_slug", unique: true end create_table "job_categories", force: :cascade do |t| @@ -166,6 +179,8 @@ t.integer "status", default: 0 t.datetime "published_at" t.string "old_status" + t.string "slug" + t.index ["slug"], name: "index_posts_on_slug", unique: true t.index ["user_id"], name: "index_posts_on_user_id" end @@ -203,6 +218,8 @@ t.integer "privacy", default: 10 t.integer "status", default: 5 t.boolean "removed", default: false + t.string "slug" + t.index ["slug"], name: "index_profiles_on_slug", unique: true t.index ["user_id"], name: "index_profiles_on_user_id" end diff --git a/db/seeds/superseed.rb b/db/seeds/superseed.rb index bc3a8be..12b937e 100644 --- a/db/seeds/superseed.rb +++ b/db/seeds/superseed.rb @@ -58,6 +58,7 @@ ] # Adiciona usuários, perfis, informações pessoais +print "\n4. criando usuários " @number_of_users.times do user = FactoryBot.create(:user, :seed) profile = FactoryBot.create(:profile, :seed, user:) @@ -65,10 +66,11 @@ personal_info = FactoryBot.create(:personal_info, :seed, profile:) # Adiciona experiências profissionais - FactoryBot.create(:professional_info, :first_seed, profile:) + FactoryBot.create(:professional_info, :first_job, profile:) rand(2..7).times do - FactoryBot.create(:professional_info, :seed, profile:) + FactoryBot.create(:professional_info, :seed_job, profile:) end + FactoryBot.create(:professional_info, :current_job, profile:) # Adiciona experiências acadêmicas FactoryBot.create(:education_info, :first_seed, profile:) @@ -85,34 +87,33 @@ job_category: job_categories.sample, description: Faker::Lorem.paragraph) end + print '.' +end - # Cria um post com imagem e outros posts somente texto (WIP) +# Para cada user cria um post com imagem e de um a três sem imagens +print "\n3. criando postagens " +User.all.each do |user| html_post = %() - FactoryBot.create(:post, - :published, - title: Faker::Lorem.sentence, content: "#{Faker::Lorem.paragraphs(number: rand(3..6)).join(' ')} #{html_post}", - tag_list: [tags].sample, - user:) + FactoryBot.create(:post, :seed, user:, content: "#{Faker::Lorem.paragraphs(number: 3).join(' ')} #{html_post}") rand(1..3).times do - FactoryBot.create(:post, - :published, - title: Faker::Lorem.sentence, - content: "#{Faker::Lorem.paragraphs(number: rand(3..6)).join(' ')}", - tag_list: [tags].sample, - user:) + FactoryBot.create(:post, :seed, user:) end + print '.' end # Adiciona followers aos perfis +print "\n2. estabelecendo seguidores e seguidos " User.all.each do |user| rand(2..5).times do not_followed_profiles = Profile.all.reject { |profile| profile.following?(user.profile) } followed_profile = not_followed_profiles.sample if not_followed_profiles.any? Connection.create!(follower: user.profile, followed_profile:) unless followed_profile == user.profile end + print '.' end # Adiciona comentários e likes +print "\n1. criando comentários e dando likes " Post.all.each do |post| rand(0..10).times do FactoryBot.create(:like, likeable: post, user: User.all.reject { |user| post.likes.pluck(:user_id).include?(user.id) }.sample) @@ -123,7 +124,9 @@ FactoryBot.create(:like, likeable: comment, user: User.all.reject { |user| comment.likes.pluck(:user_id).include?(user.id) }.sample) end end + print '.' end -puts "Pronto! #{@number_of_users} usuários criados." +puts "\nPronto! #{@number_of_users} usuários criados." puts "Admin: #{admin.email}, senha: #{admin.password}" +puts "\n" diff --git a/spec/factories/posts.rb b/spec/factories/posts.rb index f4e2404..c40477d 100644 --- a/spec/factories/posts.rb +++ b/spec/factories/posts.rb @@ -1,13 +1,36 @@ FactoryBot.define do + def long_post + 'very big sentence' + end + factory :post do user title { Faker::Lorem.sentence } - content { Faker::Lorem.paragraph sentence_count: rand(35..50) } + content { Faker::Lorem.paragraph sentence_count: rand(2..12) } edited_at { Time.zone.now } trait :published do published_at { Time.zone.now } status { :published } end + + trait :seed do + content do + [ + Faker::Lorem.paragraph(sentence_count: rand(4..18)), + Faker::Lorem.paragraph(sentence_count: rand(2..18)), + Faker::Lorem.paragraph(sentence_count: rand(4..18)), + Faker::Lorem.paragraph(sentence_count: rand(4..18)), + Faker::Lorem.paragraph(sentence_count: rand(4..18)) + ].join('

') + end + tag_list do + [ + %w[tdd rubocop], %w[seeds desafios], %w[boaspraticas solid], %w[vue zoom], %w[vue desafios], + %w[codesaga desafios tdd], %w[rubocop vue seeds], %w[zoom boaspraticas solid], + %w[tdd codesaga], %w[rubocop vue desafios], %w[seeds boaspraticas zoom], %w[solid codesaga] + ].sample + end + end end end diff --git a/spec/factories/professional_infos.rb b/spec/factories/professional_infos.rb index 827a72e..fbe5106 100644 --- a/spec/factories/professional_infos.rb +++ b/spec/factories/professional_infos.rb @@ -12,22 +12,34 @@ position { %w[programador estagiário gerente].sample } end - trait :first_seed do + trait :first_job do company { Faker::Company.name } position { Faker::Job.position } + description { Faker::Lorem.sentences(number: 6) } profile start_date { Faker::Date.backward(days: Time.zone.today - profile.personal_info.birth_date + 5840) } end_date { Faker::Date.between(from: start_date, to: start_date.advance(months: rand(2..120))) } end - trait :seed do + trait :seed_job do company { Faker::Company.name } position { Faker::Job.position } + description { Faker::Lorem.sentences(number: 6) } start_date do Faker::Date.between(from: profile.professional_infos.last.end_date, to: profile.professional_infos.last.end_date.advance(months: rand(2..12))) end end_date { Faker::Date.between(from: start_date, to: start_date.advance(months: rand(2..120))) } end + + trait :current_job do + company { Faker::Company.name } + position { Faker::Job.position } + description { Faker::Lorem.sentences(number: 6) } + profile + start_date { Faker::Date.backward(days: Time.zone.today - profile.personal_info.birth_date + 5840) } + end_date {} + current_job { true } + end end end diff --git a/spec/jobs/request_invitation_job_spec.rb b/spec/jobs/request_invitation_job_spec.rb index d72a645..7b97c16 100644 --- a/spec/jobs/request_invitation_job_spec.rb +++ b/spec/jobs/request_invitation_job_spec.rb @@ -3,11 +3,7 @@ RSpec.describe RequestInvitationJob, type: :job do it 'altera a solicitação de convite para pending caso receba uma confirmação de sucesso do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, - project_id: invitation_request.project_id, - profile_id: invitation_request.profile.id, - email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + invitation_request_params = { invitation_request_id: invitation_request.id }.as_json json_proposal_response = File.read(Rails.root.join('./spec/support/json/proposal_201.json')) fake_portfoliorrr_response = double('faraday_response', status: :ok, body: json_proposal_response) @@ -30,11 +26,7 @@ it 'enfileira um novo job caso receba um aviso de erro no servidor do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, - project_id: invitation_request.project_id, - profile_id: invitation_request.profile.id, - email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + invitation_request_params = { invitation_request_id: invitation_request.id }.as_json fake_colabora_response_body = { 'errors': ['Erro interno de servidor.'] }.as_json fake_portfoliorrr_response = double('faraday_response', status: :ok, body: fake_colabora_response_body) @@ -57,11 +49,7 @@ it 'altera a solicitação de convite para error caso receba um aviso de erro do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, - project_id: invitation_request.project_id, - profile_id: invitation_request.profile.id, - email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + invitation_request_params = { invitation_request_id: invitation_request.id }.as_json fake_colabora_response_body = { 'errors': ['Usuário já faz parte deste projeto'] }.as_json fake_portfoliorrr_response = double('faraday_response', status: :ok, body: fake_colabora_response_body) @@ -84,11 +72,7 @@ it 'altera a solicitação de convite para aborted se receber pela quinta vez um erro da API do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, - project_id: invitation_request.project_id, - profile_id: invitation_request.profile.id, - email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + invitation_request_params = { invitation_request_id: invitation_request.id }.as_json fake_colabora_response_body = { 'errors': ['Erro interno de servidor.'] }.as_json fake_portfoliorrr_response = double('faraday_response', status: :ok, body: fake_colabora_response_body) @@ -114,11 +98,7 @@ it 'gera uma nova tentativa caso a API do Portfoliorrr esteja fora do ar, sem limite de tentativas' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, - project_id: invitation_request.project_id, - profile_id: invitation_request.profile.id, - email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + invitation_request_params = { invitation_request_id: invitation_request.id }.as_json fake_response_body = { 'error': 'Houve um erro interno no servidor ao processar sua solicitação.' }.as_json fake_portfoliorrr_response = double('faraday_response', status: :internal_server_error, body: fake_response_body) diff --git a/spec/mailer/connections_mailer_spec.rb b/spec/mailer/connections_mailer_spec.rb index 9656f87..ecffb2f 100644 --- a/spec/mailer/connections_mailer_spec.rb +++ b/spec/mailer/connections_mailer_spec.rb @@ -14,7 +14,8 @@ expect(mail.subject).to include 'Alguém seguiu seu perfil' expect(mail.to).to eq [followed_profile.email] expect(mail.from).to eq ['notifications@portfoliorrr.com'] - expect(mail.body).to include 'Danilo Martins começou a seguir você' + expect(mail.body).to include "" + expect(mail.body).to include 'Danilo Martins começou a seguir você' end end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 217d17f..5c2c04c 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -248,4 +248,35 @@ expect(Connection.active.count).to eq 2 end end + + describe '#order_by_premium' do + it 'retorna perfis premium primeiro e depois os perfis free' do + create(:user, :free, full_name: 'André Porteira') + create(:user, :free, full_name: 'Eliseu Ramos') + create(:user, full_name: 'Moisés Campus') + user_premium_inactive = create(:user, full_name: 'Joao Almeida') + user_premium_inactive.subscription.inactive! + + result = Profile.order_by_premium + + expect(result.first.full_name).to eq 'Moisés Campus' + expect(result.second.full_name).to eq 'André Porteira' + expect(result.third.full_name).to eq 'Eliseu Ramos' + expect(result.fourth.full_name).to eq 'Joao Almeida' + end + + it 'ordena por nome em caso de mesmo status de assinatura' do + create(:user, :free, full_name: 'André Almeida') + create(:user, :free, full_name: 'André Barbosa') + create(:user, full_name: 'André Campus') + create(:user, full_name: 'André Dias') + + result = Profile.order_by_premium + + expect(result.first.full_name).to eq 'André Campus' + expect(result.second.full_name).to eq 'André Dias' + expect(result.third.full_name).to eq 'André Almeida' + expect(result.fourth.full_name).to eq 'André Barbosa' + end + end end diff --git a/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb b/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb index c02a437..39d086b 100644 --- a/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb +++ b/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb @@ -4,25 +4,19 @@ context 'GET /api/v1/projects/request_invitation' do it 'com sucesso e recebe confirmação da criação de proposal' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s, - project_id: invitation_request.project_id.to_s, - profile_id: invitation_request.profile.id.to_s, + invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + message: invitation_request.message, + profile_id: invitation_request.profile.id, + project_id: invitation_request.project_id } } }.as_json json_proposal_response = File.read(Rails.root.join('./spec/support/json/proposal_201.json')) fake_colabora_response = double('faraday_response', status: 201, body: json_proposal_response) - colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response) - allow(Faraday).to receive(:new) - .with(url: 'http://localhost:3000', params: invitation_request_params['data']) - .and_return(colabora_api_connection) - allow(colabora_api_connection) - .to receive(:post) - .with('/api/v1/proposals') - .and_return(fake_colabora_response) - - get '/api/v1/projects/request_invitation', params: invitation_request_params + url = 'http://localhost:3000/api/v1/proposals' + allow(Faraday).to receive(:post).with(url, invitation_request_params['data']) + .and_return(fake_colabora_response) + get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json expect(response).to have_http_status :ok expect(response.content_type).to include 'application/json' json_response = JSON.parse(response.body) @@ -32,24 +26,19 @@ it 'com sucesso, mas recebe alerta de erro 404 do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s, - project_id: invitation_request.project_id.to_s, - profile_id: invitation_request.profile.id.to_s, + invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + message: invitation_request.message, + profile_id: invitation_request.profile.id, + project_id: invitation_request.project_id } } }.as_json + url = 'http://localhost:3000/api/v1/proposals' fake_colabora_response_body = { 'errors': ['Projeto não encontrado'] }.as_json fake_colabora_response = double('faraday_response', status: 404, body: fake_colabora_response_body) - colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response) - allow(Faraday).to receive(:new) - .with(url: 'http://localhost:3000', params: invitation_request_params['data']) - .and_return(colabora_api_connection) - allow(colabora_api_connection) - .to receive(:post) - .with('/api/v1/proposals') - .and_return(fake_colabora_response) + allow(Faraday).to receive(:post).with(url, invitation_request_params['data']) + .and_return(fake_colabora_response) - get '/api/v1/projects/request_invitation', params: invitation_request_params + get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json expect(response).to have_http_status :ok expect(response.content_type).to include 'application/json' @@ -60,24 +49,19 @@ it 'com sucesso, mas recebe alerta de erro 409 do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s, - project_id: invitation_request.project_id.to_s, - profile_id: invitation_request.profile.id.to_s, + invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + message: invitation_request.message, + profile_id: invitation_request.profile.id, + project_id: invitation_request.project_id } } }.as_json + url = 'http://localhost:3000/api/v1/proposals' fake_colabora_response_body = { 'errors': ['Usuário já faz parte deste projeto'] }.as_json fake_colabora_response = double('faraday_response', status: 409, body: fake_colabora_response_body) - colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response) - allow(Faraday).to receive(:new) - .with(url: 'http://localhost:3000', params: invitation_request_params['data']) - .and_return(colabora_api_connection) - allow(colabora_api_connection) - .to receive(:post) - .with('/api/v1/proposals') - .and_return(fake_colabora_response) + allow(Faraday).to receive(:post).with(url, invitation_request_params['data']) + .and_return(fake_colabora_response) - get '/api/v1/projects/request_invitation', params: invitation_request_params + get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json expect(response).to have_http_status :ok expect(response.content_type).to include 'application/json' @@ -88,24 +72,19 @@ it 'com sucesso, mas recebe alerta de erro 500 do Cola?Bora!' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s, - project_id: invitation_request.project_id.to_s, - profile_id: invitation_request.profile.id.to_s, + invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + message: invitation_request.message, + profile_id: invitation_request.profile.id, + project_id: invitation_request.project_id } } }.as_json + url = 'http://localhost:3000/api/v1/proposals' fake_colabora_response_body = { 'errors': ['Erro interno de servidor.'] }.as_json fake_colabora_response = double('faraday_response', status: 500, body: fake_colabora_response_body) - colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response) - allow(Faraday).to receive(:new) - .with(url: 'http://localhost:3000', params: invitation_request_params['data']) - .and_return(colabora_api_connection) - allow(colabora_api_connection) - .to receive(:post) - .with('/api/v1/proposals') - .and_return(fake_colabora_response) + allow(Faraday).to receive(:post).with(url, invitation_request_params['data']) + .and_return(fake_colabora_response) - get '/api/v1/projects/request_invitation', params: invitation_request_params + get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json expect(response).to have_http_status :ok expect(response.content_type).to include 'application/json' @@ -116,17 +95,17 @@ it 'e retorna erro interno do servidor no Portfoliorrr' do invitation_request = create(:invitation_request) - invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s, - project_id: invitation_request.project_id.to_s, - profile_id: invitation_request.profile.id.to_s, + invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id, email: invitation_request.profile.email, - message: invitation_request.message } } }.as_json + message: invitation_request.message, + profile_id: invitation_request.profile.id, + project_id: invitation_request.project_id } } }.as_json - allow(Faraday).to receive(:new) - .with(url: 'http://localhost:3000', params: invitation_request_params['data']) - .and_raise(ActiveRecord::ConnectionNotEstablished) + url = 'http://localhost:3000/api/v1/proposals' + allow(Faraday).to receive(:post).with(url, invitation_request_params['data']) + .and_raise(ActiveRecord::ConnectionNotEstablished) - get '/api/v1/projects/request_invitation', params: invitation_request_params + get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json expect(response).to have_http_status :internal_server_error json_response = JSON.parse(response.body) diff --git a/spec/requests/apis/v1/search_user_by_job_categories_spec.rb b/spec/requests/apis/v1/search_user_by_job_categories_spec.rb index b8a5ccb..4c821f1 100644 --- a/spec/requests/apis/v1/search_user_by_job_categories_spec.rb +++ b/spec/requests/apis/v1/search_user_by_job_categories_spec.rb @@ -67,13 +67,13 @@ expect(json_response['data'].class).to eq Array expect(json_response['data'].first.keys).not_to include 'created_at' expect(json_response['data'].first.keys).not_to include 'updated_at' - expect(json_response['data'].first['profile_id']).to eq 1 - expect(json_response['data'].first['full_name']).to eq 'Joao Almeida' - expect(json_response['data'].first['job_categories']).to eq [{ 'name' => 'Ruby on Rails', - 'description' => 'Especialista em Ruby.' }] - expect(json_response['data'].second['profile_id']).to eq 2 - expect(json_response['data'].second['full_name']).to eq 'André Porteira' - expect(json_response['data'].second['job_categories']).to eq [] + expect(json_response['data'].first['profile_id']).to eq 2 + expect(json_response['data'].first['full_name']).to eq 'André Porteira' + expect(json_response['data'].first['job_categories']).to eq [] + expect(json_response['data'].second['profile_id']).to eq 1 + expect(json_response['data'].second['full_name']).to eq 'Joao Almeida' + expect(json_response['data'].second['job_categories']).to eq [{ 'name' => 'Ruby on Rails', + 'description' => 'Especialista em Ruby.' }] end it 'retorna um erro interno do servidor' do @@ -86,5 +86,39 @@ expect(json_response.class).to eq Hash expect(json_response['error']).to eq 'Houve um erro interno no servidor ao processar sua solicitação.' end + + it 'retorna perfis premium primeiro e depois os perfis comuns' do + create(:user, :free, full_name: 'Eliseu Ramos') + create(:user, :free, full_name: 'André Porteira') + create(:user, full_name: 'Moisés Campus') + create(:user, full_name: 'Joao Almeida') + + get '/api/v1/profiles' + + expect(response.status).to eq 200 + json_response = JSON.parse(response.body) + expect(json_response['data'].count).to eq 4 + expect(json_response['data'].first['full_name']).to eq 'Joao Almeida' + expect(json_response['data'].second['full_name']).to eq 'Moisés Campus' + expect(json_response['data'].third['full_name']).to eq 'André Porteira' + expect(json_response['data'].fourth['full_name']).to eq 'Eliseu Ramos' + end + + it 'retorna perfis premium primeiro e depois os perfis free na busca com parâmetro' do + ruby = create(:job_category, name: 'Ruby on Rails') + + user_premium = create(:user, full_name: 'Moisés Campus') + user_premium.profile.profile_job_categories.create(job_category: ruby, description: 'Sou um especialista em Ruby') + user_free = create(:user, :free, full_name: 'André Almeida') + user_free.profile.profile_job_categories.create(job_category: ruby, description: 'Fiz um e-commerce em Ruby') + + get '/api/v1/profiles', params: { search: 'ruby' } + + expect(response.status).to eq 200 + json_response = JSON.parse(response.body) + expect(json_response['data'].count).to eq 2 + expect(json_response['data'].first['full_name']).to eq 'Moisés Campus' + expect(json_response['data'].second['full_name']).to eq 'André Almeida' + end end end diff --git a/spec/services/invitation_request_service/colabora_invitation_request_post_spec.rb b/spec/services/invitation_request_service/colabora_invitation_request_post_spec.rb new file mode 100644 index 0000000..8d8830e --- /dev/null +++ b/spec/services/invitation_request_service/colabora_invitation_request_post_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe InvitationRequestService::ColaBoraInvitationRequestPost do + context '.send' do + it 'retorna a resposta da requisição feita ao ColaBora' do + invitation_request = create(:invitation_request) + fake_colabora_body = File.read(Rails.root.join('./spec/support/json/proposal_201.json')) + fake_colabora_response = double('faraday_response', status: 201, body: fake_colabora_body) + allow(Faraday).to receive(:post).and_return(fake_colabora_response) + + response = InvitationRequestService::ColaBoraInvitationRequestPost.send(invitation_request) + + json_response = JSON.parse(response.body) + expect(json_response.class).to eq Hash + expect(json_response['data']['proposal_id']).to eq 1 + end + end +end diff --git a/spec/services/projects_service/colabora_api_get_projects_spec.rb b/spec/services/projects_service/colabora_api_get_projects_spec.rb new file mode 100644 index 0000000..ebfcffa --- /dev/null +++ b/spec/services/projects_service/colabora_api_get_projects_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe ProjectsService::ColaBoraApiGetProjects do + context '.send' do + it 'retorna array de objetos do tipo Project' do + json_data = File.read(Rails.root.join('./spec/support/json/projects.json')) + fake_response = double('faraday_response', success?: true, body: json_data) + + allow(Faraday).to receive(:get).with('http://localhost:3000/api/v1/projects').and_return(fake_response) + + result = ProjectsService::ColaBoraApiGetProjects.send + + json_response = JSON.parse(result.body) + expect(json_response.class).to eq Array + expect(json_response.count).to eq 4 + end + end +end diff --git a/spec/services/invitation_request_service/colabora_project_spec.rb b/spec/services/projects_service/colabora_project_spec.rb similarity index 82% rename from spec/services/invitation_request_service/colabora_project_spec.rb rename to spec/services/projects_service/colabora_project_spec.rb index 8dcab46..7917426 100644 --- a/spec/services/invitation_request_service/colabora_project_spec.rb +++ b/spec/services/projects_service/colabora_project_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe InvitationRequestService::ColaboraProject do +RSpec.describe ProjectsService::ColaBoraProject do context '.send' do it 'retorna array de objetos do tipo Project' do json_data = File.read(Rails.root.join('./spec/support/json/projects.json')) @@ -20,9 +20,9 @@ category: 'Industrial') ] allow(Faraday).to receive(:get).with('http://localhost:3000/api/v1/projects').and_return(fake_response) - allow(InvitationRequestService::ColaboraProject).to receive(:build_projects).and_return(projects) + allow(ProjectsService::ColaBoraProject).to receive(:build_projects).and_return(projects) - result = InvitationRequestService::ColaboraProject.send + result = ProjectsService::ColaBoraProject.send expect(result.class).to eq Array expect(result.count).to eq 4 @@ -33,7 +33,7 @@ fake_response = double('faraday_response', success?: false, status: :internal_server_error) allow(Faraday).to receive(:get).with('http://localhost:3000/api/v1/projects').and_return(fake_response) - expect { InvitationRequestService::ColaboraProject.send }.to raise_error(StandardError) + expect { ProjectsService::ColaBoraProject.send }.to raise_error(StandardError) end end end diff --git a/spec/system/authentication/visitor_logs_in_spec.rb b/spec/system/authentication/visitor_logs_in_spec.rb index 08d533f..75eeec6 100644 --- a/spec/system/authentication/visitor_logs_in_spec.rb +++ b/spec/system/authentication/visitor_logs_in_spec.rb @@ -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 diff --git a/spec/system/connections/user_follows_another_user_spec.rb b/spec/system/connections/user_follows_another_user_spec.rb index abdea9e..ce3dd7e 100644 --- a/spec/system/connections/user_follows_another_user_spec.rb +++ b/spec/system/connections/user_follows_another_user_spec.rb @@ -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.profile.slug) 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) @@ -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 @@ -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) diff --git a/spec/system/connections/user_unfollows_another_user_spec.rb b/spec/system/connections/user_unfollows_another_user_spec.rb index 445afbd..bac86ea 100644 --- a/spec/system/connections/user_unfollows_another_user_spec.rb +++ b/spec/system/connections/user_unfollows_another_user_spec.rb @@ -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) diff --git a/spec/system/connections/user_views_followers_spec.rb b/spec/system/connections/user_views_followers_spec.rb index 14e5290..7581ef4 100644 --- a/spec/system/connections/user_views_followers_spec.rb +++ b/spec/system/connections/user_views_followers_spec.rb @@ -44,7 +44,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 diff --git a/spec/system/connections/user_views_following_users_spec.rb b/spec/system/connections/user_views_following_users_spec.rb index ca3dc57..07ffa42 100644 --- a/spec/system/connections/user_views_following_users_spec.rb +++ b/spec/system/connections/user_views_following_users_spec.rb @@ -44,6 +44,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 diff --git a/spec/system/education_info/user_creates_education_info_spec.rb b/spec/system/education_info/user_creates_education_info_spec.rb index 005fa91..fbb60ba 100644 --- a/spec/system/education_info/user_creates_education_info_spec.rb +++ b/spec/system/education_info/user_creates_education_info_spec.rb @@ -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' diff --git a/spec/system/education_info/user_edits_education_info_spec.rb b/spec/system/education_info/user_edits_education_info_spec.rb index 41dd54f..f4d2b7c 100644 --- a/spec/system/education_info/user_edits_education_info_spec.rb +++ b/spec/system/education_info/user_edits_education_info_spec.rb @@ -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' diff --git a/spec/system/invitations/user_views_invitations_spec.rb b/spec/system/invitations/user_views_invitations_spec.rb index dab5e0b..770f2f5 100644 --- a/spec/system/invitations/user_views_invitations_spec.rb +++ b/spec/system/invitations/user_views_invitations_spec.rb @@ -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)}" @@ -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 diff --git a/spec/system/job_categories/admin_create_job_category_spec.rb b/spec/system/job_categories/admin_create_job_category_spec.rb index e95af39..2665fbe 100644 --- a/spec/system/job_categories/admin_create_job_category_spec.rb +++ b/spec/system/job_categories/admin_create_job_category_spec.rb @@ -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 diff --git a/spec/system/notifications/user_sees_new_follower_notification_spec.rb b/spec/system/notifications/user_sees_new_follower_notification_spec.rb index 2e78d64..72b6dd8 100644 --- a/spec/system/notifications/user_sees_new_follower_notification_spec.rb +++ b/spec/system/notifications/user_sees_new_follower_notification_spec.rb @@ -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 diff --git a/spec/system/personal_info/user_edits_personal_info_spec.rb b/spec/system/personal_info/user_edits_personal_info_spec.rb index 9c23dfc..cc2b3df 100644 --- a/spec/system/personal_info/user_edits_personal_info_spec.rb +++ b/spec/system/personal_info/user_edits_personal_info_spec.rb @@ -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 diff --git a/spec/system/posts/user_creates_post_spec.rb b/spec/system/posts/user_creates_post_spec.rb index 6ebc5d4..4c259de 100644 --- a/spec/system/posts/user_creates_post_spec.rb +++ b/spec/system/posts/user_creates_post_spec.rb @@ -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 diff --git a/spec/system/posts/user_edits_post_spec.rb b/spec/system/posts/user_edits_post_spec.rb index f2deff6..425c55b 100644 --- a/spec/system/posts/user_edits_post_spec.rb +++ b/spec/system/posts/user_edits_post_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -134,7 +134,7 @@ other_user = create(:user, citizen_id_number: '61328427056', email: 'visitor@email.com') 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' diff --git a/spec/system/posts/user_views_post_list_spec.rb b/spec/system/posts/user_views_post_list_spec.rb index c5eed89..15659ae 100644 --- a/spec/system/posts/user_views_post_list_spec.rb +++ b/spec/system/posts/user_views_post_list_spec.rb @@ -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 @@ -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 @@ -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') diff --git a/spec/system/posts/visitor_views_post_spec.rb b/spec/system/posts/visitor_views_post_spec.rb index 23aa44f..df5c740 100644 --- a/spec/system/posts/visitor_views_post_spec.rb +++ b/spec/system/posts/visitor_views_post_spec.rb @@ -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) diff --git a/spec/system/professional_info/user_creates_professional_info_spec.rb b/spec/system/professional_info/user_creates_professional_info_spec.rb index 24bb8cc..49c1463 100644 --- a/spec/system/professional_info/user_creates_professional_info_spec.rb +++ b/spec/system/professional_info/user_creates_professional_info_spec.rb @@ -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' @@ -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' diff --git a/spec/system/professional_info/user_edits_professional_info_spec.rb b/spec/system/professional_info/user_edits_professional_info_spec.rb index 4e462f7..258fbdb 100644 --- a/spec/system/professional_info/user_edits_professional_info_spec.rb +++ b/spec/system/professional_info/user_edits_professional_info_spec.rb @@ -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' @@ -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 diff --git a/spec/system/profile/user_views_profile_spec.rb b/spec/system/profile/user_views_profile_spec.rb index d7cc611..2b2b8fb 100644 --- a/spec/system/profile/user_views_profile_spec.rb +++ b/spec/system/profile/user_views_profile_spec.rb @@ -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 diff --git a/spec/system/reports/admin_sees_reports_listing_page_spec.rb b/spec/system/reports/admin_sees_reports_listing_page_spec.rb index b13dfa1..28cb320 100644 --- a/spec/system/reports/admin_sees_reports_listing_page_spec.rb +++ b/spec/system/reports/admin_sees_reports_listing_page_spec.rb @@ -96,7 +96,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 diff --git a/spec/system/reports/user_report_spec.rb b/spec/system/reports/user_report_spec.rb index 077e2f0..c26669a 100644 --- a/spec/system/reports/user_report_spec.rb +++ b/spec/system/reports/user_report_spec.rb @@ -31,7 +31,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 @@ -209,7 +209,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 diff --git a/spec/system/searches/user_searches_post_by_tag_spec.rb b/spec/system/searches/user_searches_post_by_tag_spec.rb index 149e382..e6ea0db 100644 --- a/spec/system/searches/user_searches_post_by_tag_spec.rb +++ b/spec/system/searches/user_searches_post_by_tag_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/system/searches/user_searches_spec.rb b/spec/system/searches/user_searches_spec.rb index 40daee1..08916e2 100644 --- a/spec/system/searches/user_searches_spec.rb +++ b/spec/system/searches/user_searches_spec.rb @@ -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 diff --git a/spec/system/searches/users_searchs_others_users_spec.rb b/spec/system/searches/users_searchs_others_users_spec.rb index ed346d7..6811761 100644 --- a/spec/system/searches/users_searchs_others_users_spec.rb +++ b/spec/system/searches/users_searchs_others_users_spec.rb @@ -15,7 +15,6 @@ fill_in 'Buscar', with: 'gErAl' click_on 'Pesquisar' - expect(current_path).to eq searches_path expect(page).to have_content('2 resultados para: gErAl') expect(page).not_to have_content 'Horácio Fernandes' expect(page).to have_link 'Geraldo José' @@ -26,6 +25,7 @@ within 'h2' do expect(page).to have_content 'Resultados da Pesquisa' end + expect(current_path).to eq searches_path end it 'e não encontra nenhum usuário' do diff --git a/spec/system/settings/user_changes_profile_to_private_spec.rb b/spec/system/settings/user_changes_profile_to_private_spec.rb index 43d11bb..b80b5bb 100644 --- a/spec/system/settings/user_changes_profile_to_private_spec.rb +++ b/spec/system/settings/user_changes_profile_to_private_spec.rb @@ -28,10 +28,10 @@ fill_in 'Buscar', with: 'C++' click_on 'Pesquisar' - expect(current_path).to eq searches_path expect(page).to have_content('1 resultado para: C++') expect(page).not_to have_content private_user.full_name expect(page).to have_content public_user.full_name + expect(current_path).to eq searches_path end it 'e dados aparecem aos seguidores' do