fix specs

This commit is contained in:
Klaus Zanders
2025-01-15 10:58:00 +01:00
parent 1dcea35945
commit fbdbecfa12
5 changed files with 19 additions and 16 deletions
@@ -62,9 +62,10 @@ module TimeEntries
end
def user_allowed_to_modify_ongoing?(time_entry)
model.user == user && (user.allowed_in_project?(:log_time,
time_entry.project) || user.allowed_in_work_package?(:log_own_time,
time_entry.work_package))
model.user == user && (
user.allowed_in_project?(:log_time, time_entry.project) ||
user.allowed_in_work_package?(:log_own_time, time_entry.work_package)
)
end
end
end
@@ -168,10 +168,11 @@ class TimeEntriesController < ApplicationController
def load_or_build_and_authorize_time_entry
@time_entry = if params[:id]
TimeEntry.visible.find_by(id: params[:id]).tap do |entry|
if entry.blank? || !TimeEntries::UpdateContract.new(entry, current_user).user_allowed_to_update?
deny_access(not_found: true)
end
entry = TimeEntry.find_by(id: params[:id])
if entry.blank? || !TimeEntries::UpdateContract.new(entry, current_user).user_allowed_to_update?
deny_access(not_found: true)
else
entry
end
else
TimeEntry.new(project: @project, work_package: @work_package, user: User.current)
+6 -6
View File
@@ -28,7 +28,7 @@
require_relative "../spec_helper"
RSpec.describe "Work Package timer", :js do
RSpec.describe "Work Package timer", :js, :selenium do
shared_let(:project) { create(:project_with_types) }
shared_let(:work_package_a) { create(:work_package, subject: "WP A", project:) }
@@ -128,7 +128,7 @@ RSpec.describe "Work Package timer", :js do
end
context "when user has permission to log time" do
let(:permissions) { %i[log_own_time edit_own_time_entries view_own_time_entries view_work_packages] }
let(:permissions) { %i[log_own_time edit_own_time_entries view_own_time_entries view_work_packages view_project] }
it_behaves_like "allows time tracking"
@@ -164,7 +164,7 @@ RSpec.describe "Work Package timer", :js do
expect(page).to have_css(".op-timer-stop-modal")
expect(page).to have_text("Tracking time:")
page.within(".spot-modal") { click_button "Stop current timer" }
page.within(".spot-modal") { click_on "Stop current timer" }
time_logging_modal.is_visible true
time_logging_modal.has_field_with_value "spent_on", Date.current.strftime
@@ -197,7 +197,7 @@ RSpec.describe "Work Package timer", :js do
end
context "when user has no permission to log time" do
let(:permissions) { %i[view_work_packages] }
let(:permissions) { %i[view_work_packages view_project] }
it "does not show the timer" do
wp_view_a.visit!
@@ -209,13 +209,13 @@ RSpec.describe "Work Package timer", :js do
end
context "when user has permission to add, but not edit or view" do
let(:permissions) { %i[view_work_packages log_own_time] }
let(:permissions) { %i[view_work_packages log_own_time view_project] }
it_behaves_like "allows time tracking"
end
context "when user has permission to add and view but not edit" do
let(:permissions) { %i[view_work_packages log_own_time view_own_logged_time] }
let(:permissions) { %i[view_work_packages log_own_time view_own_logged_time view_project] }
it_behaves_like "allows time tracking"
end
@@ -30,7 +30,8 @@ require "spec_helper"
require_relative "../../support/pages/my/page"
RSpec.describe "My page time entries current user widget spec", :js do
# Test is flaky when using cuprite, but steady with selenium
RSpec.describe "My page time entries current user widget spec", :js, :selenium do
let!(:type) { create(:type) }
let!(:project) { create(:project, types: [type]) }
let!(:activity) { create(:time_entry_activity) }
@@ -288,7 +289,7 @@ RSpec.describe "My page time entries current user widget spec", :js do
uncheck "Monday" # the day visible_time_entry is logged for
click_button "Apply"
click_on "Apply"
within entries_area.area do
expect(page)
@@ -145,7 +145,7 @@ module Components
private
def modal_container
page.find("dialog#time-entry-dialog")
page.find("dialog#time-entry-dialog", visible: :all)
end
end
end