Skip to content
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

KG - Fix SystemSurvey Display order Sorting #1276

Merged
merged 2 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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