Skip to content

Commit

Permalink
adapt spec setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts committed Jun 20, 2024
1 parent 4285ace commit 7aa8030
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require "spec_helper"

RSpec.describe "Global menu item for boards", :js, :with_cuprite do
shared_let(:project) { create(:project) }
let(:boards_label) { I18n.t("boards.label_boards") }

before do
Expand Down
9 changes: 2 additions & 7 deletions modules/boards/spec/features/menu_items/top_menu_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
require "spec_helper"

RSpec.describe "Top menu item for boards", :js, :with_cuprite do
let(:user) { create(:admin) }
current_user { create(:admin) }
shared_let(:project) { create(:project) }

let(:menu) { find(".op-app-menu a[title='#{I18n.t('label_modules')}']") }
let(:boards) { I18n.t("boards.label_boards") }

before do
allow(User).to receive(:current).and_return user
end

shared_examples_for "the boards menu item" do
it "sends the user to the boards overview when clicked" do
menu.click
Expand All @@ -52,8 +49,6 @@
end

context "when in the project settings" do
let!(:project) { create(:project) }

before do
visit "/projects/#{project.identifier}/settings/general"
end
Expand Down
18 changes: 4 additions & 14 deletions modules/meeting/spec/controllers/meetings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@
require "#{File.dirname(__FILE__)}/../spec_helper"

RSpec.describe MeetingsController do
let(:user) { create(:admin) }
let(:project) { create(:project) }
let(:other_project) { create(:project) }
shared_let(:user) { create(:admin) }
shared_let(:project) { create(:project) }
shared_let(:other_project) { create(:project) }

before do
allow(User).to receive(:current).and_return user

allow(Project).to receive(:find).and_return(project)

allow(controller).to receive(:authorize)
allow(controller).to receive(:authorize_global)
allow(controller).to receive(:check_if_login_required)
end
current_user { user }

describe "GET" do
describe "index" do
Expand Down Expand Up @@ -161,8 +153,6 @@
let(:meeting_params) { base_meeting_params }

before do
allow(Project).to receive(:find).and_return(project)

post :create,
params:
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
:with_cuprite do
shared_let(:user_without_permissions) { create(:user) }
shared_let(:admin) { create(:admin) }
shared_let(:project) { create(:project) }
shared_let(:meetings_label) { I18n.t(:label_meeting_plural) }

let(:meetings_page) { Pages::Meetings::Index.new(project: nil) }
Expand Down
2 changes: 2 additions & 0 deletions modules/reporting/spec/features/top_menu_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
require "spec_helper"

RSpec.describe "Top menu items", :js do
shared_let(:project) { create(:project) }

let(:user) { create(:user) }
let(:open_menu) { true }

Expand Down
6 changes: 5 additions & 1 deletion modules/reporting/spec/workers/cost_query/export_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
require "spec_helper"

RSpec.describe CostQuery::ExportJob do
let(:user) { build_stubbed(:admin) }
let(:user) { build_stubbed(:user) }
let(:project) { build_stubbed(:project) }

let(:initial_filter_params) do
Expand All @@ -46,6 +46,10 @@
}
end

before do
mock_permissions_for(user, &:allow_everything)
end

# Performs a cost export with the given extra filters.
#
# @param extra_filters [Hash] A hash of attribute names and operator/value
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/activities_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

RSpec.describe ActivitiesController do
shared_let(:admin) { create(:admin) }
shared_let(:project) { create(:project) }

current_user { admin }

before do
Expand Down
13 changes: 4 additions & 9 deletions spec/controllers/news_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@

include BecomeMember

let(:user) do
create(:admin)
end
let(:project) { create(:project) }
let(:news) { create(:news) }

before do
allow(User).to receive(:current).and_return user
end
shared_let(:project) { create(:project) }
current_user { create(:admin) }

describe "#index" do
it "renders index" do
Expand Down Expand Up @@ -101,7 +96,7 @@
describe "#create" do
context "with news_added notifications" do
it "persists a news item" do
become_member(project, user)
become_member(project, current_user)

post :create,
params: {
Expand All @@ -117,7 +112,7 @@
news = News.find_by!(title: "NewsControllerTest")
expect(news).not_to be_nil
expect(news.description).to eq "This is the description"
expect(news.author).to eq user
expect(news.author).to eq current_user
expect(news.project).to eq project
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/custom_fields/create_long_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:cf_page) { Pages::CustomFields.new }
let(:editor) { Components::WysiwygEditor.new "#custom_field_form" }
let(:type) { create(:type_task) }
let(:project) { create(:project, enabled_module_names: %i[work_package_tracking], types: [type]) }
let!(:project) { create(:project, enabled_module_names: %i[work_package_tracking], types: [type]) }

let(:wp_page) { Pages::FullWorkPackageCreate.new project: }

Expand Down
1 change: 1 addition & 0 deletions spec/features/news/global_menu_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
RSpec.describe "News global menu item spec", :js, :with_cuprite do
shared_let(:admin) { create(:admin) }
shared_let(:user_without_permissions) { create(:user) }
shared_let(:project) { create(:project) }

before do
login_as current_user
Expand Down
4 changes: 2 additions & 2 deletions spec/features/projects/global_menu_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
require "spec_helper"

RSpec.describe "Projects global menu item", :js, :with_cuprite do
let(:user) { create(:user) }
current_user { create(:user) }
shared_let(:project) { create(:project) }

before do
login_as user
visit root_path
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/types/form_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
shared_let(:admin) { create(:admin) }
let(:type) { create(:type) }

let(:project) { create(:project, types: [type]) }
let!(:project) { create(:project, types: [type]) }
let(:category) { create(:category, project:) }
let(:work_package) do
create(:work_package,
Expand Down
9 changes: 4 additions & 5 deletions spec/features/work_packages/work_package_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
require "spec_helper"

RSpec.describe "Work Packages", "index view", :js, :with_cuprite do
let(:user) { create(:admin) }
let(:project) { create(:project, enabled_module_names: %w[work_package_tracking]) }
shared_let(:user) { create(:admin) }
shared_let(:project) { create(:project, enabled_module_names: %w[work_package_tracking]) }

let(:wp_table) { Pages::WorkPackagesTable.new(project) }

before do
login_as(user)
end
current_user { user }

context "within a global context" do
before do
Expand Down
1 change: 1 addition & 0 deletions spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
include Rack::Test::Methods
include API::V3::Utilities::PathHelper

shared_let(:project) { create(:project) }
current_user { create(:admin) }

context "when enabled", with_config: { rate_limiting: { api_v3: true } } do
Expand Down

0 comments on commit 7aa8030

Please sign in to comment.