Skip to content

Commit

Permalink
Add default_scope to StagingProject
Browse files Browse the repository at this point in the history
because otherwise using ActiveRecord query methods will consider
all Projects and not only StagingProjects.
This causes some weird issues like returning Projects without
a Staging::Workflow associated.
  • Loading branch information
ChrisBr committed Nov 15, 2018
1 parent cd52a6a commit 8a06eb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/app/models/staging/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class StagingProject < Project
has_many :status_reports, through: :repositories, inverse_of: :checkable
belongs_to :staging_workflow, class_name: 'Staging::Workflow'

default_scope { where.not(staging_workflow: nil) }

def staging_identifier
name[/.*:Staging:(.*)/, 1]
end
Expand Down
3 changes: 2 additions & 1 deletion src/api/app/models/staging/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def ignored_requests

def create_staging_projects
['A', 'B'].each do |letter|
staging_project = Staging::StagingProject.find_or_initialize_by(name: "#{project.name}:Staging:#{letter}")
parent = Project.find_or_initialize_by(name: "#{project.name}:Staging:#{letter}")
staging_project = parent.becomes(Staging::StagingProject)
next if staging_project.staging_workflow # if it belongs to another staging workflow skip it
staging_project.staging_workflow = self
staging_project.store
Expand Down

0 comments on commit 8a06eb9

Please sign in to comment.