Skip to content

Instantly share code, notes, and snippets.

@JustinChristensen
Created February 23, 2012 03:01
Show Gist options
  • Save JustinChristensen/1889586 to your computer and use it in GitHub Desktop.
Save JustinChristensen/1889586 to your computer and use it in GitHub Desktop.
class SurveyReportOrderByColumnTest < ActiveSupport::TestCase
setup do
@survey_report = FormBuilder::SurveyReport.new(:survey_id => 132, :name => "Foo Bar Report")
@survey_report.data = {'576' => 1, '577' => 2, '578' => 3}
@survey_report.filters = []
@ordered_dates_asc = ["03/30/1962", "03/30/1979", "09/01/2000", "05/11/2008"]
@ordered_dates_desc = @ordered_dates_asc.reverse
@ordered_names_asc = ["Bob", "Coach", "Third", "tom"]
@ordered_names_desc = @ordered_names_asc.reverse
@ordered_volunteer_info_asc = ["Coach", "Communication", "Equipment Manager", "Timekeeper"]
@ordered_volunteer_info_desc = @ordered_volunteer_info_asc.reverse
end
test "first name does not have display column and sorts by survey column" do
entries = @survey_report.entries(:sorting_order_by => 576, :sorting_dir => 'ASC')
entries.collect! { |entry| entry[1] }
assert_equal @ordered_names_asc, entries
assert_not_equal @ordered_names_desc, entries
end
test "date has display column but sorts by survey column" do
entries = @survey_report.entries(:sorting_order_by => 577, :sorting_dir => 'ASC')
entries.collect! { |entry| entry[2] }
assert_equal @ordered_dates_asc, entries
assert_not_equal @ordered_dates_desc, entries
# RAAAAAAGGGGEEE!?!?
entries = @survey_report.entries(:sorting_order_by => 577, :sorting_dir => 'DESC')
entries.collect! { |entry| entry[2] }
assert_equal @ordered_dates_desc, entries
assert_not_equal @ordered_dates_asc, entries
end
test "volunteer options has display column and sorts by display column" do
entries = @survey_report.entries(:sorting_order_by => 578, :sorting_dir => 'ASC')
entries.collect! { |entry| entry[3] }
assert_equal @ordered_volunteer_info_asc, entries
assert_not_equal @ordered_volunteer_info_desc, entries
end
end
# Returns:
SurveyReportOrderByColumnTest
test_date_has_display_column_but_sorts_by_survey_column FAIL
test/unit/form_builder/survey_report_test.rb:366:in `test_date_has_display_column_but_sorts_by_survey_column'
<["05/11/2008", "09/01/2000", "03/30/1979", "03/30/1962"]> expected but was
<[47, 47, 47, 47]>.
test_first_name_does_not_have_display_column_and_sorts_by_survey_column PASS
test_volunteer_options_has_display_column_and_sorts_by_display_column PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment