From 83b93b9c5a1439ded467171b834208aa8b00dcbb Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 7 Dec 2013 00:28:01 +0000 Subject: [PATCH] Add some more unit tests for the Trace model --- test/traces/3.gpx | Bin 0 -> 410 bytes test/unit/trace_test.rb | 42 ++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 test/traces/3.gpx diff --git a/test/traces/3.gpx b/test/traces/3.gpx new file mode 100644 index 0000000000000000000000000000000000000000..cdfa9413be112520c9d19715775fe651f6048b48 GIT binary patch literal 410 zcmV;L0cHL|T4*^jL0KkKS-pep~96KSdGJX23l2c*yjk5fQ&Af9ZUB4S?J z1VvQxlH}A)l^(oZEC6md$rFM`JU0Of`-|Gup2%>QS~M;TZJ$azR<=mR4h@SkP#fg{ zYp<}R+NfK{l!}4e)CEcANInZ|M+mg33|kgyx$M5-Xg<_GR3LQSlQ(6&x?Kbe5U8X= z0eTx!2z<`#Qr((Sxl;#woy^U`G|d=PKtU^oc;|yGS1*5VA)bDRI5kkf;B)D*ROGFP z-m1n>@czS7m-4CAlfJAW+pY+;*(pM6TGmn{#~MjW(pMByof7*E4RJLh=10UtyzUHW zacJJEBr5un8|K0Xlx$QEWDG)qSw?eLjooGml!#4Ws}7S1l18CjcH&DchEB?tDHg)B zRi>Ra{#$X*IOOL{*Z@j~3?Fo<5eNhoBv4-bL&*_DK#A~_l8M3N(?|Hbk}1N3h3p@1 EDC&u~H2?qr literal 0 HcmV?d00001 diff --git a/test/unit/trace_test.rb b/test/unit/trace_test.rb index f840d6c5c..d2720e993 100644 --- a/test/unit/trace_test.rb +++ b/test/unit/trace_test.rb @@ -3,22 +3,38 @@ require File.dirname(__FILE__) + '/../test_helper' class TraceTest < ActiveSupport::TestCase api_fixtures + def setup + @gpx_trace_dir = Object.send("remove_const", "GPX_TRACE_DIR") + Object.const_set("GPX_TRACE_DIR", File.dirname(__FILE__) + "/../traces") + end + + def teardown + Object.send("remove_const", "GPX_TRACE_DIR") + Object.const_set("GPX_TRACE_DIR", @gpx_trace_dir) + end + def test_trace_count assert_equal 5, Trace.count end def test_visible - check_query(Trace.visible, :public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file) + check_query(Trace.visible, [:public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file]) end def test_visible_to - check_query(Trace.visible_to(1), :public_trace_file, :identifiable_trace_file) - check_query(Trace.visible_to(2), :public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file) - check_query(Trace.visible_to(3), :public_trace_file, :identifiable_trace_file) + check_query(Trace.visible_to(1), [:public_trace_file, :identifiable_trace_file]) + check_query(Trace.visible_to(2), [:public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file]) + check_query(Trace.visible_to(3), [:public_trace_file, :identifiable_trace_file]) end def test_public - check_query(Trace.public, :public_trace_file, :identifiable_trace_file, :deleted_trace_file) + check_query(Trace.public, [:public_trace_file, :identifiable_trace_file, :deleted_trace_file]) + end + + def test_tagged + check_query(Trace.tagged("London"), [:public_trace_file, :anon_trace_file]) + check_query(Trace.tagged("Birmingham"), [:anon_trace_file, :identifiable_trace_file]) + check_query(Trace.tagged("Unknown"), []) end def test_validations @@ -76,9 +92,23 @@ class TraceTest < ActiveSupport::TestCase assert_equal false, gpx_files(:deleted_trace_file).identifiable? end + def test_mime_type + assert_equal "application/gpx+xml", gpx_files(:public_trace_file).mime_type + assert_equal "application/gpx+xml", gpx_files(:anon_trace_file).mime_type + assert_equal "application/x-bzip2", gpx_files(:trackable_trace_file).mime_type + assert_equal "application/x-gzip", gpx_files(:identifiable_trace_file).mime_type + end + + def test_extension_name + assert_equal ".gpx", gpx_files(:public_trace_file).extension_name + assert_equal ".gpx", gpx_files(:anon_trace_file).extension_name + assert_equal ".gpx.bz2", gpx_files(:trackable_trace_file).extension_name + assert_equal ".gpx.gz", gpx_files(:identifiable_trace_file).extension_name + end + private - def check_query(query, *traces) + def check_query(query, traces) traces = traces.map { |t| gpx_files(t) }.sort assert_equal traces, query.order(:id) end -- 2.43.2