From 89eb74851773b8ff8f33771019700a4b9dfb84d6 Mon Sep 17 00:00:00 2001 From: Juan Roldan Date: Sat, 4 Feb 2017 05:46:26 -0300 Subject: [PATCH] Tests added for all filters - Fixtures sample setup for 'quotes' list --- Rakefile | 1 - coverage/.last_run.json | 2 +- coverage/.resultset.json | 144 ++++++++++++++++++++++++++++++++------ test/fixtures/quotes.yml | 70 ++++++++++++++++++ test/movie_quotes_test.rb | 102 +++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 23 deletions(-) create mode 100644 test/fixtures/quotes.yml diff --git a/Rakefile b/Rakefile index 444a58e..4a727bd 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,6 @@ Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList[ "test/test_helper.rb", - "test/movie_quotes/*_test.rb", "test/*_test.rb" ] t.verbose = true diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 63fe309..3cb5e70 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 52.38 + "covered_percent": 100.0 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 3dbf164..cb831a6 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -13,75 +13,75 @@ 1, null, 1, - 0, + 12, null, null, 1, - 0, + 1, null, - 0, + 1, null, null, null, 1, null, - 0, + 2, null, - 0, + 2, null, null, 1, - 0, + 1, null, - 0, + 1, null, null, 1, - 0, + 1, null, - 0, + 1, null, null, 1, - 0, + 1, null, - 0, + 1, null, null, 1, - 0, + 1, null, - 0, + 1, null, null, null, 1, - 0, + 2, null, - 0, + 2, null, null, 1, - 0, + 1, null, null, 1, - 0, + 11, null, null, 1, null, 1, - 0, + 5, null, null, 1, null, - 0, + 4, null, null, 1, - 0, + 20, null, null ], @@ -89,6 +89,108 @@ 1, null, 1, + 1, + 12, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + 1, + 1, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + null, + null, + null, null, null, null, @@ -107,6 +209,6 @@ null ] }, - "timestamp": 1486167370 + "timestamp": 1486197350 } } diff --git a/test/fixtures/quotes.yml b/test/fixtures/quotes.yml new file mode 100644 index 0000000..b8510f5 --- /dev/null +++ b/test/fixtures/quotes.yml @@ -0,0 +1,70 @@ +--- +http_interactions: +- request: + method: get + uri: http://dev.movie-quotes.com:3000/v1/quotes + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + Content-Type: + - application/json; charset=utf-8 + Etag: + - W/"31b03015e4835bf59b420b2c4946a697" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 4a647a3d-926f-42c4-9b6c-1ed50295ddd3 + X-Runtime: + - '0.074625' + Vary: + - Origin + Transfer-Encoding: + - chunked + body: + encoding: UTF-8 + string: '[{"id":32,"content":"After all, tomorrow is another day!","year":1939,"categories":["Romance","Drama","War"],"movie":{"title":"Gone + With The Wind","slug":"gone-with-the-wind"},"character":{"name":"Scarlett + O''hara","slug":"scarlett-o-hara"},"actor":{"name":"Vivien Leigh","slug":"vivien-leigh"}},{"id":3,"content":"I''m + gonna make him an offer he can''t refuse.","year":1972,"categories":["Crime","Drama"],"movie":{"title":"The + Godfather","slug":"the-godfather"},"character":{"name":"Vito Corleone","slug":"vito-corleone"},"actor":{"name":"Marlon + Brando","slug":"marlon-brando"}},{"id":5,"content":"Toto, I''ve got a feeling + we''re not in Kansas anymore.","year":1939,"categories":["Fantasy","Drama","Adventure"],"movie":{"title":"Wizard + Of Oz, The The Wizard Of Oz","slug":"wizard-of-oz-the-the-wizard-of-oz"},"character":{"name":"Dorothy + Gale","slug":"dorothy-gale"},"actor":{"name":"Judy Garland","slug":"judy-garland"}},{"id":6,"content":"Here''s + looking at you, kid.","year":1942,"categories":["Romance","Drama","War"],"movie":{"title":"Casablanca","slug":"casablanca"},"character":{"name":"Rick + Blaine","slug":"rick-blaine"},"actor":{"name":"Humphrey Bogart","slug":"humphrey-bogart"}},{"id":21,"content":"Louis, + I think this is the beginning of a beautiful friendship.","year":1942,"categories":["Romance","Drama","War"],"movie":{"title":"Casablanca","slug":"casablanca"},"character":{"name":"Rick + Blaine","slug":"rick-blaine"},"actor":{"name":"Humphrey Bogart","slug":"humphrey-bogart"}},{"id":29,"content":"Play + it, Sam. Play ''As Time Goes By.''","year":1942,"categories":["Romance","Drama","War"],"movie":{"title":"Casablanca","slug":"casablanca"},"character":{"name":"Ilsa + Lund","slug":"ilsa-lund"},"actor":{"name":"Ingrid Bergman","slug":"ingrid-bergman"}},{"id":33,"content":"Round + up the usual suspects.","year":1942,"categories":["Romance","Drama","War"],"movie":{"title":"Casablanca","slug":"casablanca"},"character":{"name":"Capt. + Louis Renault","slug":"capt-louis-renault"},"actor":{"name":"Claude Rains","slug":"claude-rains"}},{"id":44,"content":"We''ll + always have Paris.","year":1942,"categories":["Romance","Drama","War"],"movie":{"title":"Casablanca","slug":"casablanca"},"character":{"name":"Rick + Blaine","slug":"rick-blaine"},"actor":{"name":"Humphrey Bogart","slug":"humphrey-bogart"}},{"id":7,"content":"Go + ahead, make my day.","year":1983,"categories":["Thriller","Action"],"movie":{"title":"Sudden + Impact","slug":"sudden-impact"},"character":{"name":"Harry Callahan","slug":"harry-callahan"},"actor":{"name":"Clint + Eastwood","slug":"clint-eastwood"}},{"id":25,"content":"I am big! It''s the + pictures that got small.","year":1950,"categories":["Fantasy","Drama","Adventure"],"movie":{"title":"Sunset + Boulevard","slug":"sunset-boulevard"},"character":{"name":"Norma Desmond","slug":"norma-desmond"},"actor":{"name":"Gloria + Swanson","slug":"gloria-swanson"}}]' + http_version: + recorded_at: Sat, 04 Feb 2017 08:27:39 GMT +recorded_with: VCR 3.0.3 diff --git a/test/movie_quotes_test.rb b/test/movie_quotes_test.rb index 7d40c7d..e8a956b 100644 --- a/test/movie_quotes_test.rb +++ b/test/movie_quotes_test.rb @@ -1,6 +1,108 @@ require "test_helper" describe MovieQuotes do + before do + @filter = MovieQuotes.new + end + + it "should not have any filter applied" do + @filter.filters.must_equal({}) + end + + it "should allow to see current URL" do + @filter.url.must_equal "http://dev.movie-quotes.com:3000/v1/quotes?" + end + + describe "#by_actor" do + it "should contain 'actor' param inside URL" do + @filter.by_actor("bruce") + @filter.url.must_include "actor=bruce" + end + end + + describe "#by_category" do + describe "filtering by a single category" do + it "should contain 'category' param inside URL" do + @filter.by_category("action") + @filter.url.must_include "categories[]=action" + end + end + + describe "filtering by multiple categories" do + it "should contain 'category' param inside URL" do + @filter.by_category("action,thriller") + @filter.url.must_include "categories[]=action,thriller" + end + end + end + + describe "#by_character" do + it "should contain 'character' param inside URL" do + @filter.by_character("john") + @filter.url.must_include "character=john" + end + end + + describe "#by_content" do + it "should contain 'content' param inside URL" do + @filter.by_content("motherfucker") + @filter.url.must_include "content=motherfucker" + end + end + + describe "#by_movie" do + it "should contain 'movie' param inside URL" do + @filter.by_movie("die") + @filter.url.must_include "movie=die" + end + end + + describe "#by_page" do + it "should contain 'page' param inside URL" do + @filter.by_page(2) + @filter.url.must_include "page=2" + end + end + + describe "#by_year" do + describe "filtering by a single year" do + it "should contain 'year' param inside URL" do + @filter.by_year(1988) + @filter.url.must_include "years[]=1988" + end + end + + describe "filtering by multiple years" do + it "should contain 'year' param inside URL" do + @filter.by_year("1988,2005") + @filter.url.must_include "years[]=1988,2005" + end + end + end + + describe "#results" do + it "should return an array of 'Quote' JSON objects" do + VCR.use_cassette("quotes") do + quotes = @filter.results + quote = quotes[1] + + quote["id"].must_equal 3 + quote["content"].must_equal "I'm gonna make him an offer he can't refuse." + quote["year"].must_equal 1972 + quote["categories"].must_equal ["Crime", "Drama"] + + quote["movie"]["title"].must_equal "The Godfather" + quote["movie"]["slug"].must_equal "the-godfather" + + quote["character"]["name"].must_equal "Vito Corleone" + quote["character"]["slug"].must_equal "vito-corleone" + + quote["actor"]["name"].must_equal "Marlon Brando" + quote["actor"]["slug"].must_equal "marlon-brando" + end + end + end + # describe ".configure" do # before do