diff --git a/Gemfile b/Gemfile index ca699cc0e..23ae87fd1 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'rails', '~> 7.0.7' gem 'bootsnap', require: false -gem 'activeadmin', '~> 2.13.1' +gem 'activeadmin', '~> 3.2' gem 'autoprefixer-rails', '~> 10.4.2.0' gem 'cancancan', '~> 3.3.0' gem 'carrierwave', '~> 2.2.5' @@ -47,7 +47,7 @@ gem 'business_time' gem 'github_api', '~> 0.18.2' gem 'httparty' gem 'money-rails', '~> 1.12' -gem 'ransack', '~> 2.3' +gem 'ransack', '~> 4.0' gem 'sidekiq', "~> 6.5.12" diff --git a/Gemfile.lock b/Gemfile.lock index c2735cd7d..da016ce5f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -88,15 +88,15 @@ GEM case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) active_skin (0.0.13) - activeadmin (2.13.1) + activeadmin (3.2.0) arbre (~> 1.2, >= 1.2.1) - formtastic (>= 3.1, < 5.0) - formtastic_i18n (~> 0.4) + formtastic (>= 3.1) + formtastic_i18n (>= 0.4) inherited_resources (~> 1.7) - jquery-rails (~> 4.2) - kaminari (~> 1.0, >= 1.2.1) - railties (>= 6.1, < 7.1) - ransack (>= 2.1.1, < 4) + jquery-rails (>= 4.2) + kaminari (>= 1.2.1) + railties (>= 6.1) + ransack (>= 4.0) activejob (7.0.7.2) activesupport (= 7.0.7.2) globalid (>= 0.3.6) @@ -123,9 +123,9 @@ GEM tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) - arbre (1.6.0) - activesupport (>= 3.0.0, < 7.1) - ruby2_keywords (>= 0.0.2, < 1.0) + arbre (1.7.0) + activesupport (>= 3.0.0) + ruby2_keywords (>= 0.0.2) ast (2.4.2) autoprefixer-rails (10.4.2.0) execjs (~> 2) @@ -249,8 +249,8 @@ GEM sassc (>= 1.11) foreman (0.87.2) formatador (1.1.0) - formtastic (4.0.0) - actionpack (>= 5.2.0) + formtastic (5.0.0) + actionpack (>= 6.0.0) formtastic_i18n (0.7.0) github_api (0.18.2) addressable (~> 2.4) @@ -275,7 +275,7 @@ GEM guard (~> 2.8) guard-compat (~> 1.0) multi_json (~> 1.8) - has_scope (0.8.1) + has_scope (0.8.2) actionpack (>= 5.2) activesupport (>= 5.2) hashdiff (1.0.1) @@ -298,11 +298,11 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inherited_resources (1.13.1) - actionpack (>= 5.2, < 7.1) - has_scope (~> 0.6) - railties (>= 5.2, < 7.1) - responders (>= 2, < 4) + inherited_resources (1.14.0) + actionpack (>= 6.0) + has_scope (>= 0.6) + railties (>= 6.0) + responders (>= 2) inline_svg (1.9.0) activesupport (>= 3.0) nokogiri (>= 1.6) @@ -347,7 +347,7 @@ GEM listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) lumberjack (1.2.8) @@ -361,7 +361,7 @@ GEM method_source (1.0.0) mini_magick (4.12.0) mini_mime (1.1.5) - mini_portile2 (2.8.2) + mini_portile2 (2.8.5) minitest (5.20.0) moneta (1.0.0) monetize (1.12.0) @@ -427,8 +427,8 @@ GEM public_suffix (5.0.4) puma (6.3.1) nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.7) + racc (1.7.3) + rack (2.2.8) rack-proxy (0.7.6) rack rack-test (2.1.0) @@ -454,7 +454,7 @@ GEM actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.1.1) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) @@ -472,10 +472,10 @@ GEM thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.0.6) - ransack (2.6.0) - activerecord (>= 6.0.4) - activesupport (>= 6.0.4) + rake (13.1.0) + ransack (4.1.1) + activerecord (>= 6.1.5) + activesupport (>= 6.1.5) i18n rate_throttle_client (0.1.2) rb-fsevent (0.11.2) @@ -485,7 +485,7 @@ GEM regexp_parser (2.8.1) request_store (1.5.1) rack (>= 1.4) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.5) @@ -596,7 +596,7 @@ GEM railties (>= 6.0.0) tailwindcss-rails (2.0.30-x86_64-linux) railties (>= 6.0.0) - thor (1.2.2) + thor (1.3.0) thread_safe (0.3.6) tilt (2.2.0) timeliness (0.4.5) @@ -631,7 +631,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.8) + zeitwerk (2.6.12) PLATFORMS aarch64-linux @@ -646,7 +646,7 @@ DEPENDENCIES active_admin_theme active_model_serializers (~> 0.10.13) active_skin - activeadmin (~> 2.13.1) + activeadmin (~> 3.2) autoprefixer-rails (~> 10.4.2.0) barnes better_errors @@ -703,7 +703,7 @@ DEPENDENCIES rails-ajax_redirect rails-controller-testing rails-i18n - ransack (~> 2.3) + ransack (~> 4.0) rollbar roo (~> 2.9.0) rqrcode diff --git a/app/models/allocation.rb b/app/models/allocation.rb index ec444628d..5c25ae020 100644 --- a/app/models/allocation.rb +++ b/app/models/allocation.rb @@ -20,19 +20,20 @@ class Allocation < ApplicationRecord delegate :name, to: :project, prefix: true, allow_nil: true delegate :name, to: :user, prefix: true, allow_nil: true - scope :ongoing, -> { + scope :ongoing, lambda { where(ongoing: true, user_id: User.active).order(start_at: :desc) } - scope :finished, -> { - where(ongoing: false, user_id: User.active).order(end_at: :desc) } - scope :in_period, -> (start_at, end_at) do + scope :finished, lambda { + where(ongoing: false, user_id: User.active).order(end_at: :desc) + } + scope :in_period, lambda { |start_at, end_at| where( "daterange(start_at, end_at, '[]') && daterange(:start_at, :end_at, '[]')", - start_at: start_at, - end_at: end_at + start_at:, + end_at: ) - end + } def days_until_finish return unless end_at @@ -53,12 +54,21 @@ def self.hourly_rate_currencies def user_punches project .punches - .where(user: user) + .where(user:) .since(start_at) .order(from: :desc) .decorate end + def self.ransackable_attributes(_auth_object = nil) + %w[created_at end_at hourly_rate_cents hourly_rate_currency id ongoing project_id start_at + updated_at user_id] + end + + def self.ransackable_associations(_auth_object = nil) + %w[project user] + end + private def end_before_start? @@ -66,7 +76,7 @@ def end_before_start? end def unique_period - return unless Allocation.in_period(start_at, end_at).where.not(id: id).exists?(user_id: user_id) + return unless Allocation.in_period(start_at, end_at).where.not(id:).exists?(user_id:) errors.add(:start_at, :overlapped_period) end diff --git a/app/models/city.rb b/app/models/city.rb index dd4a21e8e..d6768f199 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -16,4 +16,8 @@ def to_s def holidays regional_holidays.to_formatted_hash end + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at id name state_id updated_at] + end end diff --git a/app/models/contribution.rb b/app/models/contribution.rb index 98a9af0ac..317f47343 100644 --- a/app/models/contribution.rb +++ b/app/models/contribution.rb @@ -76,6 +76,15 @@ def update_rejected_reason(rejected_reason = "other_reason", reviewer_id) scope :by_created_at_from, ->(date) { where('created_at >= ?', date) if date.present? } scope :by_created_at_until, ->(date) { where('created_at <= ?', date) if date.present? } + def self.ransackable_attributes(_auth_object = nil) + %w[created_at description id link notes pending pr_state rejected_reason repository_id + reviewed_at reviewer_id state tracking updated_at] + end + + def self.ransackable_associations(_auth_object = nil) + %w[repository reviewed_by users] + end + private def normalize_description_blank_value diff --git a/app/models/education_experience.rb b/app/models/education_experience.rb index 9a683e252..ed20a60ad 100644 --- a/app/models/education_experience.rb +++ b/app/models/education_experience.rb @@ -16,4 +16,12 @@ class EducationExperience < ApplicationRecord allow_nil: true scope :for_user, ->(user_id) { where(user_id:) } + + def self.ransackable_associations(_auth_object = nil) + ["user"] + end + + def self.ransackable_attributes(_auth_object = nil) + %w[course created_at end_date id institution start_date updated_at user_id] + end end diff --git a/app/models/evaluation.rb b/app/models/evaluation.rb index 7e329468b..daa4a1d31 100644 --- a/app/models/evaluation.rb +++ b/app/models/evaluation.rb @@ -21,12 +21,21 @@ class Evaluation < ApplicationRecord attribute :evaluation_date, :date, default: Time.zone.today - scope :by_kind, -> (kind) { joins(:questionnaire).merge(Questionnaire.public_send(kind)) } + scope :by_kind, ->(kind) { joins(:questionnaire).merge(Questionnaire.public_send(kind)) } enumerize :english_level, in: { beginner: 0, intermediate: 1, advanced: 2, fluent: 3 - }, scope: :shallow, - predicates: true + }, scope: :shallow, + predicates: true + + def self.ransackable_associations(_auth_object = nil) + %w[answers evaluated evaluator questionnaire] + end + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at english_level evaluated_id evaluation_date evaluator_id id observation + questionnaire_id score updated_at] + end private diff --git a/app/models/office.rb b/app/models/office.rb index 6072a77a2..3ad36bda3 100644 --- a/app/models/office.rb +++ b/app/models/office.rb @@ -2,7 +2,7 @@ class Office < ApplicationRecord has_many :users, dependent: :restrict_with_error - has_many :users_without_head, ->(office) {where.not(id: office.head_id)}, class_name: 'User' + has_many :users_without_head, ->(office) { where.not(id: office.head_id) }, class_name: 'User' belongs_to :head, class_name: 'User', optional: true validates :city, presence: true, uniqueness: true @@ -22,4 +22,12 @@ def calculate_score users_average_score = users_overall_scores.sum / users_overall_scores.size update(score: users_average_score.round(2)) end + + def self.ransackable_associations(_auth_object = nil) + %w[head users users_without_head] + end + + def self.ransackable_attributes(_auth_object = nil) + %w[active city created_at head_id id score updated_at users_count] + end end diff --git a/app/models/project.rb b/app/models/project.rb index ad98ba2aa..1b254752e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -31,4 +31,12 @@ def enable! def to_s name end + + def self.ransackable_attributes(_auth_object = nil) + %w[active created_at id market name updated_at] + end + + def self.ransackable_associations(_auth_object = nil) + %w[allocations punches] + end end diff --git a/app/models/punch.rb b/app/models/punch.rb index c1c7169b7..4a7aa5889 100644 --- a/app/models/punch.rb +++ b/app/models/punch.rb @@ -7,7 +7,7 @@ class Punch < ApplicationRecord belongs_to :user validates_presence_of :from, :to - validates [:from, :to], check_time: true + validates %i[from to], check_time: true validates_with WorkableValidator, if: -> { from.present? && user.present? } mount_uploader :attachment, AttachmentUploader @@ -16,12 +16,14 @@ class Punch < ApplicationRecord scope :until, ->(time) { where('punches.to <= ?', time) } scope :by_days, ->(days) { where('date("punches"."from") in (?)', days) } scope :is_extra_hour, -> { where extra_hour: true } - scope :from_last_month, -> { + scope :from_last_month, lambda { current_month = Date.current.change day: 15 last_month = current_month.prev_month + 1.day where from: last_month..current_month } - scope :filter_by_date, -> (user_id, from, to) { where('user_id = ? AND created_at >= ? AND created_at <= ?', user_id, from.to_datetime, to.to_datetime) } + scope :filter_by_date, lambda { |user_id, from, to| + where('user_id = ? AND created_at >= ? AND created_at <= ?', user_id, from.to_datetime, to.to_datetime) + } delegate :name, to: :user, prefix: true delegate :name, to: :project, prefix: true @@ -29,19 +31,16 @@ class Punch < ApplicationRecord def from_time=(time_string) @from_time = time_string.presence mount_times - time_string end def to_time=(time_string) @to_time = time_string.presence mount_times - time_string end def when_day=(date) @when_day = date.presence mount_times - date end def delta @@ -59,8 +58,8 @@ def date end def sheet - as_json(only: [:project_id, :from, :to]).merge( - delta: (delta/1.hour).round + as_json(only: %i[project_id from to]).merge( + delta: (delta / 1.hour).round ) end @@ -68,6 +67,14 @@ def self.total all.reduce(0) { |a, e| a + e.delta } end + def self.ransackable_attributes(_auth_object = nil) + %w[attachment comment created_at extra_hour from id project_id to updated_at user_id] + end + + def self.ransackable_associations(_auth_object = nil) + %w[project user] + end + private def mount_time(time_string) @@ -75,9 +82,9 @@ def mount_time(time_string) end def mount_times - unless @when_day.nil? - self.to = mount_time(@to_time) unless @to_time.nil? - self.from = mount_time(@from_time) unless @from_time.nil? - end + return if @when_day.nil? + + self.to = mount_time(@to_time) unless @to_time.nil? + self.from = mount_time(@from_time) unless @from_time.nil? end end diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index be793d03b..7148fae4f 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -32,4 +32,12 @@ def toggle_active def to_s title end + + def self.ransackable_attributes(_auth_object = nil) + %w[active created_at description id kind title updated_at] + end + + def self.ransackable_associations(_auth_object = nil) + %w[evaluations questions] + end end diff --git a/app/models/regional_holiday.rb b/app/models/regional_holiday.rb index 04c0e2e76..0dbcadc5b 100644 --- a/app/models/regional_holiday.rb +++ b/app/models/regional_holiday.rb @@ -14,6 +14,14 @@ def cities_names cities.pluck(:name).to_sentence end + def self.ransackable_attributes(_auth_object = nil) + %w[created_at day id month name updated_at] + end + + def self.ransackable_associations(_auth_object = nil) + ["cities"] + end + private def valid_date? diff --git a/app/models/repository.rb b/app/models/repository.rb index e77467be1..ef4c6f5ae 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -8,10 +8,12 @@ def to_s end scope :with_distinct_languages, -> { group(:language).select(:language).where.not(language: [nil, '']) } - scope :by_repository_name_like, ->(repository_name) { - if repository_name.present? - where("link ILIKE ?", "%#{repository_name}%") - end + scope :by_repository_name_like, lambda { |repository_name| + where("link ILIKE ?", "%#{repository_name}%") if repository_name.present? } scope :by_languages, ->(languages) { where(language: languages) if languages.present? } + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at description highlight id issues language link stars updated_at] + end end diff --git a/app/models/skill.rb b/app/models/skill.rb index 14bfea0e4..f97d698c5 100644 --- a/app/models/skill.rb +++ b/app/models/skill.rb @@ -9,4 +9,8 @@ class Skill < ApplicationRecord uniqueness: { case_sensitive: false } scope :by_title_like, ->(title) { where("skills.title ILIKE ?", "%#{title}%") if title.present? } + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at id title updated_at] + end end diff --git a/app/models/talk.rb b/app/models/talk.rb index 9523e578d..a675b167f 100644 --- a/app/models/talk.rb +++ b/app/models/talk.rb @@ -6,6 +6,14 @@ class Talk < ApplicationRecord validates :event_name, :talk_title, :date, presence: true validate :future_date? + def self.ransackable_associations(_auth_object = nil) + ["user"] + end + + def self.ransackable_attributes(_auth_object = nil) + %w[created_at date event_name id talk_title updated_at user_id] + end + private def future_date? diff --git a/app/models/user.rb b/app/models/user.rb index 159d7551e..780ad05f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,26 +13,26 @@ class User < ApplicationRecord %i[backend_level frontend_level].each do |specialty| enumerize specialty, - in: { trainee: 6, intern: 0, junior: 1, junior_plus: 2, mid: 3, mid_plus: 4, senior: 5 }, - scope: :shallow, - predicates: true, - i18n_scope: 'enumerize.user.level' + in: { trainee: 6, intern: 0, junior: 1, junior_plus: 2, mid: 3, mid_plus: 4, senior: 5 }, + scope: :shallow, + predicates: true, + i18n_scope: 'enumerize.user.level' end enumerize :occupation, in: { administrative: 0, engineer: 1 - }, scope: :shallow, - predicates: true + }, scope: :shallow, + predicates: true enumerize :specialty, in: { frontend: 0, backend: 1, devops: 2, mobile: 4, qa: 5 - }, scope: :shallow, - predicates: true + }, scope: :shallow, + predicates: true enumerize :contract_type, in: { internship: 0, employee: 1, contractor: 2, associate: 3 - }, scope: :shallow, - predicates: true + }, scope: :shallow, + predicates: true enumerize :contract_company_country, in: { brazil: 0, usa: 1 } @@ -41,7 +41,7 @@ class User < ApplicationRecord admin: 2, open_source_manager: 3, hr: 4, - commercial: 5, + commercial: 5 }, multiple: true, predicates: true belongs_to :office, optional: false @@ -78,14 +78,14 @@ class User < ApplicationRecord scope :allocated, -> { engineer.active.where(id: Allocation.ongoing.select(:user_id)) } scope :by_skills_in, ->(*skill_ids) { UsersBySkillsQuery.where(ids: skill_ids) } scope :not_in_experience, -> { where arel_table[:created_at].lt(EXPERIENCE_PERIOD.ago) } - scope :by_roles_in, -> roles { + scope :by_roles_in, lambda { |roles| roles_values = self.roles.find_values(*roles).map(&:value) where("users.roles && ARRAY[?]::int[]", roles_values) } scope :admin, -> { by_roles_in([:admin]) } scope :hr, -> { by_roles_in([:hr]) } scope :commercial, -> { by_roles_in([:commercial]) } - scope :vacation_managers, -> { by_roles_in([:hr, :commercial]) } + scope :vacation_managers, -> { by_roles_in(%i[hr commercial]) } scope :by_name_like, ->(name) { where("users.name ILIKE ?", "%#{name}%") } scope :by_email_like, ->(email) { where("users.email ILIKE ?", "%#{email}%") } @@ -105,10 +105,23 @@ def self.ransackable_scopes(_auth_object) [:by_skills_in] end + def self.ransackable_attributes(_auth_object = nil) + %w[active allow_overtime backend_level city_id confirmation_sent_at + confirmed_at consumed_timestep contract_company_country contract_type created_at current_sign_in_at + email frontend_level github id last_sign_in_at mentor_id name observation occupation office_id + remember_created_at roles specialty started_at updated_at] + end + + def self.ransackable_associations(_auth_object = nil) + %w[allocations authored_notes city contributions education_experiences evaluations + managed_offices mentees mentor notes office professional_experiences projects punches skills talks user_skills vacations] + end + def self.overall_score_average overall_scores = all.map(&:overall_score).compact return 0 if overall_scores.empty? + (overall_scores.sum / overall_scores.size).round(2) end @@ -174,11 +187,9 @@ def update_with_password(params, *options) if current_password.blank? super else - errors.add(:password, "não pode ficar em branco") if password.blank? - errors.add(:password_confirmation, "não pode ficar em branco") if password_confirmation.blank? - if password_confirmation != password - errors.add(:password_confirmation, "não é igual a Password") - end + errors.add(:password, "não pode ficar em branco") if password.blank? + errors.add(:password_confirmation, "não pode ficar em branco") if password_confirmation.blank? + errors.add(:password_confirmation, "não é igual a Password") if password_confirmation != password end errors.present? ? false : super diff --git a/app/models/vacation.rb b/app/models/vacation.rb index 4ae3b6717..edc397aa2 100644 --- a/app/models/vacation.rb +++ b/app/models/vacation.rb @@ -15,56 +15,55 @@ class Vacation < ApplicationRecord pending: 0, approved: 1, denied: 2, - cancelled: 3, + cancelled: 3 }, predicates: true, scope: :shallow validates_presence_of :start_date, :end_date, :user validates_comparison_of :start_date, - message: -> (_vacation, _other) { - I18n.t( - "activerecord.errors.models.vacation.attributes.start_date.greater_than_current", - date: I18n.l(Date.current) - ) - }, - greater_than: -> (_) { Date.current }, - allow_nil: true, - if: :not_cancelled? + message: lambda { |_vacation, _other| + I18n.t( + "activerecord.errors.models.vacation.attributes.start_date.greater_than_current", + date: I18n.l(Date.current) + ) + }, + greater_than: ->(_) { Date.current }, + allow_nil: true, + if: :not_cancelled? validates_comparison_of :end_date, - message: -> (vacation, _other) { - I18n.t( - "activerecord.errors.models.vacation.attributes.end_date.greater_than_current", - date: I18n.l(vacation.start_date + MINIMUM_RANGE_OF_DAYS.days) - ) - }, - greater_than: -> (vacation) { vacation.start_date + MINIMUM_RANGE_OF_DAYS.days }, - allow_nil: true, - if: :not_cancelled? + message: lambda { |vacation, _other| + I18n.t( + "activerecord.errors.models.vacation.attributes.end_date.greater_than_current", + date: I18n.l(vacation.start_date + MINIMUM_RANGE_OF_DAYS.days) + ) + }, + greater_than: ->(vacation) { vacation.start_date + MINIMUM_RANGE_OF_DAYS.days }, + allow_nil: true, + if: :not_cancelled? validate :validate_start_date_close_to_weekend, if: :start_date, unless: -> { user.contractor? } validates_with HolidayValidator, if: :start_date, unless: -> { !validate_vacation_before_holiday? } - scope :ongoing_and_scheduled, -> { + scope :ongoing_and_scheduled, lambda { where(status: :approved) - .where("end_date >= :today", today: Date.current) - .order(start_date: :asc, end_date: :asc) + .where("end_date >= :today", today: Date.current) + .order(start_date: :asc, end_date: :asc) } - scope :expired, -> { + scope :expired, lambda { pending - .where("start_date < :today", today: Date.current) - .order(start_date: :asc, end_date: :asc) + .where("start_date < :today", today: Date.current) + .order(start_date: :asc, end_date: :asc) } - scope :pending_approval_of, ->(approver) { - unless [:hr, :commercial].include? approver.to_sym - raise ArgumentError, "The approver should be :hr or :commercial" - end + scope :pending_approval_of, lambda { |approver| + raise ArgumentError, "The approver should be :hr or :commercial" unless %i[hr commercial].include? approver.to_sym + where("#{approver}_approver_id": nil) } - scope :finished, -> { + scope :finished, lambda { approved - .where("end_date <= :today", today: Date.current) - .order(end_date: :desc) + .where("end_date <= :today", today: Date.current) + .order(end_date: :desc) } def approve!(user) @@ -82,7 +81,7 @@ def deny!(user) def cancel!(user) update!(status: :cancelled, denier: user) - end + end def cancelable? pending? || approved_within_cancel_range? @@ -92,6 +91,15 @@ def duration_days (start_date..end_date).count end + def self.ransackable_associations(_auth_object = nil) + %w[commercial_approver denier hr_approver user] + end + + def self.ransackable_attributes(_auth_object = nil) + %w[commercial_approver_id created_at denier_id end_date hr_approver_id id start_date status + updated_at user_id] + end + private def approved_within_cancel_range? @@ -107,9 +115,9 @@ def not_cancelled? end def validate_start_date_close_to_weekend - if start_date.thursday? || start_date.friday? || start_date.on_weekend? - errors.add(:start_date, :close_weekend) - end + return unless start_date.thursday? || start_date.friday? || start_date.on_weekend? + + errors.add(:start_date, :close_weekend) end def validate_vacation_before_holiday? diff --git a/spec/admin/contributions_controller.spec.rb b/spec/admin/contributions_controller_spec.rb similarity index 84% rename from spec/admin/contributions_controller.spec.rb rename to spec/admin/contributions_controller_spec.rb index 95e5ea31e..55fc26d0c 100644 --- a/spec/admin/contributions_controller.spec.rb +++ b/spec/admin/contributions_controller_spec.rb @@ -15,8 +15,8 @@ allow(controller).to receive(:authenticate_user!) allow(controller).to receive(:current_user).and_return(admin) end - - describe 'GET index' do + + describe 'GET index' do it 'renders the index template' do get :index expect(response).to render_template(:index) @@ -41,8 +41,7 @@ it 'renders the form elements' do get :new - expect(page).to have_field('contribution[user_id]') - .and have_field('contribution[repository_id]') + expect(page).to have_field('contribution[repository_id]') .and have_field('contribution[link]') end end @@ -53,18 +52,17 @@ let(:contribution_params) do { - "link"=>"https://github.com/Codeminer", - "user_id"=>user.id, - "repository_id"=>repository.id + "link" => "https://github.com/Codeminer", + "user_id" => user.id, + "repository_id" => repository.id } end context 'with valid params' do it 'creates a new Contribution' do - - expect { + expect do post :create, params: { contribution: contribution_params } - }.to change(Contribution, :count).by(1) + end.to change(Contribution, :count).by(1) end it 'assigns a newly created contribution as @contribution' do @@ -87,13 +85,6 @@ expect(contribution.link).to eq(contribution_params['link']) end - it 'ensures created contibution received correct user' do - post :create, params: { contribution: contribution_params } - contribution = Contribution.last - - expect(contribution.user_id).to eq(user.id) - end - it 'ensures created contibution received correct repository' do post :create, params: { contribution: contribution_params } contribution = Contribution.last @@ -133,10 +124,9 @@ it 'renders the form elements' do get :show, params: { id: contribution_to_show.id } - expect(page).to have_content(contribution_to_show.user) - .and have_content(contribution_to_show.link) + expect(page).to have_content(contribution_to_show.link) .and have_content(Contribution.human_attribute_name("state/#{contribution_to_show.state}")) - end + end end describe 'GET edit' do @@ -144,7 +134,7 @@ it 'has http status 200' do get :edit, params: { id: contribution.id } - + expect(response).to have_http_status(:ok) end @@ -160,9 +150,9 @@ let(:contribution) { create(:contribution) } it 'updates contribution\'s state' do - params = { id: contribution.id, state: 'approved'} + params = { id: contribution.id, state: 'approved' } - patch :update, params: params + patch(:update, params:) expect(response).to redirect_to admin_contribution_path end end @@ -173,7 +163,7 @@ it 'does not update contribution\'s state' do params = { id: contribution.id, state: 'approved', rejected_reason: :other_reason } - patch :update, params: params + patch(:update, params:) expect(contribution.reload.state).to eq('received') end @@ -181,8 +171,8 @@ it 'redirects to the same page' do params = { id: contribution.id, state: 'approved', rejected_reason: :other_reason } - patch :update, params: params - + patch(:update, params:) + expect(response).to redirect_to admin_contribution_path end end diff --git a/spec/admin/professional_experience.rb b/spec/admin/professional_experience_spec.rb similarity index 100% rename from spec/admin/professional_experience.rb rename to spec/admin/professional_experience_spec.rb diff --git a/spec/features/admin/evaluations_spec.rb b/spec/features/admin/evaluations_spec.rb index 0e1520f3c..876bf3f07 100644 --- a/spec/features/admin/evaluations_spec.rb +++ b/spec/features/admin/evaluations_spec.rb @@ -82,8 +82,8 @@ within '#filters_sidebar_section' do expect(page).to have_css('label', text: 'Criado em') - fill_in 'q_created_at_gteq_datetime', with: 9.months.ago - fill_in 'q_created_at_lteq_datetime', with: 7.months.ago + fill_in 'q_created_at_gteq', with: 9.months.ago + fill_in 'q_created_at_lteq', with: 7.months.ago click_button 'Filtrar' end @@ -114,11 +114,12 @@ end describe 'Actions' do - let!(:evaluation) { create(:evaluation, - :with_answers, - answer_count: 2, - english_level: 'beginner' - )} + let!(:evaluation) do + create(:evaluation, + :with_answers, + answer_count: 2, + english_level: 'beginner') + end before do visit '/admin/evaluations' diff --git a/spec/requests/new_admin/questionnaires_controller_spec.rb b/spec/requests/new_admin/questionnaires_controller_spec.rb index 6bae295b6..4a414317e 100644 --- a/spec/requests/new_admin/questionnaires_controller_spec.rb +++ b/spec/requests/new_admin/questionnaires_controller_spec.rb @@ -32,13 +32,13 @@ context 'when title filter is applied' do let!(:foo_questionnaire) { create(:questionnaire, title: 'Foo') } - let!(:bar_questionnaire) { create(:questionnaire, title: 'Bar') } + let!(:bar_questionnaire) { create(:questionnaire, title: 'Weird title') } it 'returns only the filtered questionnaires', :aggregate_failures do get new_admin_questionnaires_path, params: { title: 'foo' } expect(response.body).to include('Foo') - expect(response.body).not_to include('Bar') + expect(response.body).not_to include('Weird title') end end