Skip to content

Commit

Permalink
Fix the QueriesController so that the user is the proper owner of the…
Browse files Browse the repository at this point in the history
… query
  • Loading branch information
Klaus Zanders committed May 22, 2024
1 parent 4b2877d commit 070fe4f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions spec/controllers/projects/queries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

context "when logged in" do
let(:query) { build_stubbed(:project_query) }
let(:query) { build_stubbed(:project_query, user:) }
let(:query_id) { "42" }
let(:query_params) { double }

Expand Down Expand Up @@ -77,7 +77,7 @@
end

context "when logged in" do
let(:query) { build_stubbed(:project_query) }
let(:query) { build_stubbed(:project_query, user:) }
let(:query_params) { double }
let(:service_instance) { instance_double(service_class) }
let(:service_result) { instance_double(ServiceResult, success?: success?, result: query) }
Expand Down Expand Up @@ -148,7 +148,7 @@
end

context "when logged in" do
let(:query) { build_stubbed(:project_query) }
let(:query) { build_stubbed(:project_query, user:) }
let(:query_id) { "42" }
let(:query_params) { double }
let(:service_instance) { instance_double(service_class) }
Expand All @@ -157,7 +157,9 @@

before do
allow(controller).to receive(:permitted_query_params).and_return(query_params)
allow(Queries::Projects::ProjectQuery).to receive(:find).with(query_id).and_return(query)
scope = instance_double(ActiveRecord::Relation)
allow(Queries::Projects::ProjectQuery).to receive(:visible).and_return(scope)
allow(scope).to receive(:find).with(query_id).and_return(query)
allow(service_class).to receive(:new).with(model: query, user:).and_return(service_instance)
allow(service_instance).to receive(:call).with(query_params).and_return(service_result)

Expand Down Expand Up @@ -219,12 +221,15 @@
end

context "when logged in" do
let(:query) { build_stubbed(:project_query) }
let(:query) { build_stubbed(:project_query, user:) }
let(:query_id) { "42" }
let(:service_instance) { instance_spy(service_class) }

before do
allow(Queries::Projects::ProjectQuery).to receive(:find).with(query_id).and_return(query)
scope = instance_double(ActiveRecord::Relation)
allow(Queries::Projects::ProjectQuery).to receive(:visible).and_return(scope)
allow(scope).to receive(:find).with(query_id).and_return(query)

allow(service_class).to receive(:new).with(model: query, user:).and_return(service_instance)

login_as user
Expand Down

0 comments on commit 070fe4f

Please sign in to comment.