Skip to content

Remove scratch projects scope filter #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ module Types
validate :project_with_school_id_has_school_project
validate :school_project_school_matches_project_school

default_scope -> { where.not(project_type: Types::SCRATCH) }

scope :internal_projects, -> { where(user_id: nil) }
scope :only_scratch, lambda { |only_scratch|
only_scratch ? unscoped.where(project_type: Project::Types::SCRATCH) : self
only_scratch ? Project.where(project_type: Project::Types::SCRATCH) : self
}

has_paper_trail(
Expand Down
18 changes: 9 additions & 9 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@
describe 'default scope' do
let!(:python_project) { create(:project, project_type: Project::Types::PYTHON) }
let!(:html_project) { create(:project, project_type: Project::Types::HTML) }
let!(:project_with_unknown_type) { create(:project, project_type: 'unknown') }
let!(:scratch_project) { create(:project, project_type: Project::Types::SCRATCH) }
let!(:project_with_unknown_type) { create(:project, project_type: 'unknown') }

it 'includes python projects' do
expect(described_class.all).to include(python_project)
Expand All @@ -334,12 +334,12 @@
expect(described_class.all).to include(html_project)
end

it 'includes projects with unknown type' do
expect(described_class.all).to include(project_with_unknown_type)
it 'includes scratch projects' do
expect(described_class.all).to include(scratch_project)
end

it 'does not include scratch projects' do
expect(described_class.all).not_to include(scratch_project)
it 'includes projects with unknown type' do
expect(described_class.all).to include(project_with_unknown_type)
end
end

Expand All @@ -362,12 +362,12 @@
expect(projects_in_scope).to include(html_project)
end

it 'includes projects with unknown type' do
expect(projects_in_scope).to include(project_with_unknown_type)
it 'includes scratch projects' do
expect(projects_in_scope).to include(scratch_project)
end

it 'does not include scratch projects' do
expect(projects_in_scope).not_to include(scratch_project)
it 'includes projects with unknown type' do
expect(projects_in_scope).to include(project_with_unknown_type)
end
end

Expand Down
12 changes: 0 additions & 12 deletions spec/requests/projects/remix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
let(:original_project_type) { Project::Types::SCRATCH }
let(:project_type) { Project::Types::SCRATCH }

it 'returns 404 response if scratch projects are not explicitly included' do
get("/api/projects/#{original_project.identifier}/remix", headers:)

expect(response).to have_http_status(:not_found)
end

it 'returns success response if scratch projects are explicitly included' do
get("/api/projects/#{original_project.identifier}/remix?project_type=scratch", headers:)

Expand Down Expand Up @@ -128,12 +122,6 @@
context 'when original project is scratch project' do
let(:original_project_type) { Project::Types::SCRATCH }

it 'returns 404 response if scratch projects are not explicitly included' do
post("/api/projects/#{original_project.identifier}/remix", params: { project: project_params }, headers:)

expect(response).to have_http_status(:not_found)
end

it 'returns success response if scratch projects are explicitly included' do
post("/api/projects/#{original_project.identifier}/remix?project_type=scratch", params: { project: project_params }, headers:)

Expand Down
5 changes: 0 additions & 5 deletions spec/requests/projects/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@
expect(response.body).to eq(starter_project_json)
end
end

it 'returns 404 response if scratch project' do
get("/api/projects/#{starter_project.identifier}?locale=#{starter_project.locale}", headers:)
expect(response).to have_http_status(:not_found)
end
end

it 'creates a new ProjectLoader with the correct parameters' do
Expand Down