Skip to content

Commit

Permalink
Merge pull request #1276 from sparc-request/kg-survey_display_order_bug
Browse files Browse the repository at this point in the history
KG - Fix SystemSurvey Display order Sorting
  • Loading branch information
Stuart-Johnson committed Mar 23, 2018
2 parents 90ce901 + 4f717d9 commit b03a206
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/models/system_survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class SystemSurvey < Survey
# 2 surveys can't have the same access code and both be active
validates_uniqueness_of :active, scope: [:type, :access_code], if: -> { self.active }

default_scope -> {
order(:display_order)
}

def self.yaml_klass
Survey.name
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/surveyor/surveys/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
.bootstrap-table-dropdown-overflow
#surveys-custom-toolbar
= link_to t(:surveyor)[:systemsurveys][:new], surveyor_surveys_path(type: 'SystemSurvey'), method: :post, remote: true, class: "btn btn-success", id: "new-survey-button"
%table.survey-table{ data: { toggle: 'table', search: 'true', 'show-columns' => 'true', 'show-refresh' => 'true', 'show-toggle' => 'true', url: surveyor_surveys_path(type: 'SystemSurvey'), striped: 'true', toolbar: '#surveys-custom-toolbar', pagination: 'true', page_size: '20' } }
%table.survey-table{ data: { toggle: 'table', search: 'true', 'show-columns' => 'true', 'show-refresh' => 'true', 'show-toggle' => 'true', url: surveyor_surveys_path(type: 'SystemSurvey'), striped: 'true', toolbar: '#surveys-custom-toolbar', pagination: 'true', page_size: '20', sort_name: 'display_order' } }
%thead.primary-header
%tr
%th.col-sm-3{ data: { field: "title", align: "left", sortable: 'true' } }
Expand Down
4 changes: 2 additions & 2 deletions spec/features/surveyor/user_edits_survey_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@
end

scenario 'and sees updated display order' do
create(:system_survey, access_code: @survey.access_code, version: @survey.version+1, display_order: 0)
@new_survey = create(:system_survey, access_code: @survey.access_code, version: @survey.version+1, display_order: 0)

visit surveyor_surveys_path
wait_for_javascript_to_finish

first('.edit-survey').click
wait_for_javascript_to_finish

bootstrap_select "#survey-#{@survey.id}-display_order", 'Add as last'
bootstrap_select "#survey-#{@new_survey.id}-display_order", 'Add as last'
wait_for_javascript_to_finish

expect(@survey.reload.display_order).to eq(2)
Expand Down

0 comments on commit b03a206

Please sign in to comment.