From 2ea5da52b36beb0cd2aed1fa29e47bd5341a55d1 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 21:37:48 -0700 Subject: [PATCH 01/20] Fixed first test for "no profile" * stub the image_tag method * add an improved description --- refactor-this/helper_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index b82e40e..72a2526 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -14,8 +14,15 @@ @helper = Helper.new end describe "display_photo" do - it "should return the wrench if there is no profile" do - @helper.display_photo(nil, "100x100", {}, {}, true).should == "wrench.png" + describe "If the profile is not set" do + before do + @helper.stub!(:image_tag) do |img| + img + end + end + it "return the wrench" do + @helper.display_photo(nil, "100x100", {}, {}, true).should == "wrench.png" + end end describe "With a profile, user and photo requesting a link" do From 6423bede61ab8f999ec9ada605099ed73e5288c1 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 21:42:06 -0700 Subject: [PATCH 02/20] Second test passing for "With a profile, user and photo requesting a link" * added require for Rails reverse_merge library file * added stub methods for profile_path, url_for_file_column, image_tag, and link_to * change to_s to to_str in Photo class --- refactor-this/helper_spec.rb | 7 +++++++ refactor-this/photo.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 72a2526..95fb6b6 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -8,6 +8,7 @@ require 'helper' require 'user' require 'photo' +require 'active_support/core_ext/hash/reverse_merge' describe "Helper" do before(:each) do @@ -33,7 +34,13 @@ @profile.user = @user @photo = Photo.new @user.photo = @photo + @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} + + @helper.stub!(:profile_path).with(@profile).and_return("profile_path") @profile.stub!(:has_valid_photo?).and_return(true) + @helper.stub!(:url_for_file_column).with("user", "photo", "100x100").and_return("imagefile") + @helper.stub!(:image_tag).with("imagefile", @html).and_return("image_tag") + @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("this link") end it "should return a link" do @helper.display_photo(@profile, "100x100", {}, {}, true).should == "this link" diff --git a/refactor-this/photo.rb b/refactor-this/photo.rb index 88ea4c5..6407399 100644 --- a/refactor-this/photo.rb +++ b/refactor-this/photo.rb @@ -1,5 +1,5 @@ class Photo - def to_s + def to_str "photo.rb" end end \ No newline at end of file From ba0ae5e88e1fdcccc4581cedcbe767c5daf43b5a Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 21:48:53 -0700 Subject: [PATCH 03/20] Third test passing "With a profile, user and photo not requesting a link" * refactored test methods & descriptions, and created common before block --- refactor-this/helper_spec.rb | 44 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 95fb6b6..f841aa9 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -26,8 +26,8 @@ end end - describe "With a profile, user and photo requesting a link" do - before(:each) do + describe "With a profile, user" do + before do @profile = UserProfile.new @profile.name = "Clayton" @user = User.new @@ -36,30 +36,28 @@ @user.photo = @photo @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} - @helper.stub!(:profile_path).with(@profile).and_return("profile_path") @profile.stub!(:has_valid_photo?).and_return(true) @helper.stub!(:url_for_file_column).with("user", "photo", "100x100").and_return("imagefile") - @helper.stub!(:image_tag).with("imagefile", @html).and_return("image_tag") - @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("this link") - end - it "should return a link" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "this link" - end - end - - describe "With a profile, user and photo not requesting a link" do - before(:each) do - @profile = UserProfile.new - @profile.name = "Clayton" - @user = User.new - @profile.user = @user - @photo = Photo.new - @user.photo = @photo - @profile.stub!(:has_valid_photo?).and_return(true) - end - it "should just an image" do - @helper.display_photo(@profile, "100x100", {}, {}, false).should == "just image" + @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end + describe "and a user and photo requesting a link" do + before(:each) do + @helper.stub!(:image_tag).with("imagefile", @html).and_return("image_tag") + @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("this link") + end + it "return a link" do + @helper.display_photo(@profile, "100x100", {}, {}, true).should == "this link" + end + end + + describe "and photo not requesting a link" do + before(:each) do + @helper.stub!(:image_tag).with("imagefile", @html).and_return("just image") + end + it "return just an image" do + @helper.display_photo(@profile, "100x100", {}, {}, false).should == "just image" + end + end end describe "Without a user, but requesting a link" do From 865f56f1e1381e42ab956472002d0f89dc4a42b4 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 22:15:10 -0700 Subject: [PATCH 04/20] Fouth test passing: "With a profile and user without a photo and the user is a rep user" * replaced code in helper.rb with call to has_valid_photo?, which exists in user_profile.rb, and is already stubbed * regroup tests again, update describe strings, and consolidate stuff in before blocks --- refactor-this/helper.rb | 3 +- refactor-this/helper_spec.rb | 169 +++++++++++++++++------------------ 2 files changed, 84 insertions(+), 88 deletions(-) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index 6ef273b..599bce5 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -34,8 +34,7 @@ def display_photo(profile, size, html = {}, options = {}, link = true) html.reverse_merge!(:class => 'thumbnail', :size => size, :title => "Link to #{profile.name}") if profile && profile.user - if profile.user && profile.user.photo && File.exists?(profile.user.photo) - @user = profile.user + if profile.has_valid_photo? if link return link_to(image_tag(url_for_file_column("user", "photo", size), html), profile_path(profile) ) else diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index f841aa9..18dea0d 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -26,106 +26,103 @@ end end - describe "With a profile, user" do + describe "With a profile" do before do @profile = UserProfile.new @profile.name = "Clayton" - @user = User.new - @profile.user = @user - @photo = Photo.new - @user.photo = @photo - @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} - - @profile.stub!(:has_valid_photo?).and_return(true) - @helper.stub!(:url_for_file_column).with("user", "photo", "100x100").and_return("imagefile") - @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end - describe "and a user and photo requesting a link" do - before(:each) do - @helper.stub!(:image_tag).with("imagefile", @html).and_return("image_tag") - @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("this link") - end - it "return a link" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "this link" + describe "and user" do + before do + @user = User.new + @profile.user = @user + @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} + + @profile.stub!(:has_valid_photo?).and_return(true) + @helper.stub!(:url_for_file_column).with("user", "photo", "100x100").and_return("imagefile") + @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end - end + describe "and photo" do + before do + @photo = Photo.new + @user.photo = @photo + end + describe "requesting a link" do + before(:each) do + @helper.stub!(:image_tag).with("imagefile", @html).and_return("image_tag") + @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("this link") + end + it "return a link" do + @helper.display_photo(@profile, "100x100", {}, {}, true).should == "this link" + end + end + + describe "not requesting a link" do + before(:each) do + @helper.stub!(:image_tag).with("imagefile", @html).and_return("just image") + end + it "return just an image" do + @helper.display_photo(@profile, "100x100", {}, {}, false).should == "just image" + end + end + end - describe "and photo not requesting a link" do - before(:each) do - @helper.stub!(:image_tag).with("imagefile", @html).and_return("just image") - end - it "return just an image" do - @helper.display_photo(@profile, "100x100", {}, {}, false).should == "just image" - end - end + + describe "without a photo" do + before(:each) do + @profile.stub!(:has_valid_photo?).and_return(false) + end + describe "and the user is a rep user" do + before(:each) do + @user.stub!(:rep?).and_return(true) + @helper.stub!(:image_tag).with("user190x119.jpg", {}).and_return("image_tag") + @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("default link 190x119") + end + it "return a default link" do + @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 190x119" + end + end + + describe "and the user is a regular user" do + before(:each) do + @user.stub!(:rep?).and_return(false) + end + it "return a default link" do + @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" + end + end + + describe "and we don't want to display the default" do + before(:each) do + @profile.stub!(:has_valid_photo?).and_return(false) + end + describe "and the user is a rep user" do + before(:each) do + @user.stub!(:rep?).and_return(true) + end + it "return a default link" do + @helper.display_photo(@profile, "100x100", {}, {:show_default => false}, true).should == "NO DEFAULT" + end + end + + describe "and the user is a regular user" do + before(:each) do + @user.stub!(:rep?).and_return(false) + end + it "return a default link" do + @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" + end + end + end + end + end end - describe "Without a user, but requesting a link" do before(:each) do - @profile = UserProfile.new - @profile.name = "Clayton" end it "return a default" do @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" end end - describe "When the user doesn't have a photo" do - before(:each) do - @profile = UserProfile.new - @profile.name = "Clayton" - @user = User.new - @profile.user = @user - @profile.stub!(:has_valid_photo?).and_return(false) - end - describe "With a rep user" do - before(:each) do - @user.stub!(:rep?).and_return(true) - end - it "return a default link" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 190x119" - end - - end - - describe "With a regular user" do - before(:each) do - @user.stub!(:rep?).and_return(false) - end - it "return a default link" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" - end - end - end - - describe "When the user doesn't have a photo and we don't want to display the default" do - before(:each) do - @profile = UserProfile.new - @profile.name = "Clayton" - @user = User.new - @profile.user = @user - @profile.stub!(:has_valid_photo?).and_return(false) - end - describe "With a rep user" do - before(:each) do - @user.stub!(:rep?).and_return(true) - end - it "return a default link" do - @helper.display_photo(@profile, "100x100", {}, {:show_default => false}, true).should == "NO DEFAULT" - end - - end - - describe "With a regular user" do - before(:each) do - @user.stub!(:rep?).and_return(false) - end - it "return a default link" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" - end - end - end - - end end \ No newline at end of file From 47e10b64339eed0728e03b1503eb10dc41a9dda1 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 22:19:07 -0700 Subject: [PATCH 05/20] Fifth test passing: "With a profile and user without a photo and the user is a regular user" * add stub methods to get test to pass --- refactor-this/helper_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 18dea0d..b537970 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -85,6 +85,8 @@ describe "and the user is a regular user" do before(:each) do @user.stub!(:rep?).and_return(false) + @helper.stub!(:image_tag).with("user100x100.jpg", {}).and_return("image_tag") + @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("default link 100x100") end it "return a default link" do @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" From a245512febb47a5bf3752c45f65205b4ed14c780 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 22:22:58 -0700 Subject: [PATCH 06/20] Two more tests passing for 'NO DEFAULT' case * modified code to return 'NO DEFAULT' instead of empty string * changed test to check for 'NO DEFAULT' for both types of users * removed useless line from code --- refactor-this/helper.rb | 4 +--- refactor-this/helper_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index 599bce5..57d7901 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -41,11 +41,9 @@ def display_photo(profile, size, html = {}, options = {}, link = true) return image_tag(url_for_file_column("user", "photo", size), html) end else - show_default_image ? default_photo(profile, size, {}, link) : '' + show_default_image ? default_photo(profile, size, {}, link) : 'NO DEFAULT' end end - - show_default_image ? default_photo(profile, size, {}, link) : '' end def default_photo(profile, size, html={}, link = true) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index b537970..c2e8042 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -95,14 +95,14 @@ describe "and we don't want to display the default" do before(:each) do - @profile.stub!(:has_valid_photo?).and_return(false) + @options = {:show_default => false} end describe "and the user is a rep user" do before(:each) do @user.stub!(:rep?).and_return(true) end it "return a default link" do - @helper.display_photo(@profile, "100x100", {}, {:show_default => false}, true).should == "NO DEFAULT" + @helper.display_photo(@profile, "100x100", {}, @options, true).should == "NO DEFAULT" end end @@ -111,7 +111,7 @@ @user.stub!(:rep?).and_return(false) end it "return a default link" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" + @helper.display_photo(@profile, "100x100", {}, @options, true).should == "NO DEFAULT" end end end From 0553afcd2640a18f9f80c9007444cf263831e8b5 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 22:43:33 -0700 Subject: [PATCH 07/20] Final test passing: "With a profile, no user, but requesting a link" * fix placement of final test to be inside proper describe block * initialize the @html attribute and stub 'profile_path' when the @profile is created * add else section to if block in code for case with profile but no user * stub image_tag, link_to methods --- refactor-this/helper.rb | 2 ++ refactor-this/helper_spec.rb | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index 57d7901..92b233e 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -43,6 +43,8 @@ def display_photo(profile, size, html = {}, options = {}, link = true) else show_default_image ? default_photo(profile, size, {}, link) : 'NO DEFAULT' end + else + link_to(image_tag("user#{size}.jpg", html), profile_path(profile)) end end diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index c2e8042..0c592dc 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -26,20 +26,21 @@ end end - describe "With a profile" do + describe "With a profile," do before do @profile = UserProfile.new @profile.name = "Clayton" + @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} + + @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end describe "and user" do before do @user = User.new @profile.user = @user - @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} @profile.stub!(:has_valid_photo?).and_return(true) @helper.stub!(:url_for_file_column).with("user", "photo", "100x100").and_return("imagefile") - @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end describe "and photo" do before do @@ -117,14 +118,15 @@ end end end - end - describe "Without a user, but requesting a link" do - before(:each) do - end - it "return a default" do - @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" + describe "no user, but requesting a link" do + before(:each) do + @helper.stub!(:image_tag).with("user100x100.jpg", @html).and_return("image_tag") + @helper.stub!(:link_to).with("image_tag", "profile_path").and_return("default link 100x100") + end + it "return a default link" do + @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100" + end end end - end end \ No newline at end of file From 6d9d4055ae6e513aadf63ea140236924711dc91c Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 23:02:05 -0700 Subject: [PATCH 08/20] Refactor 'display_photo' code to make it simpler & more readable * remove default_photo method * url_for_file_column, image_tag, profile_path, and link_to only appear once in the code * remove comment about 'this should not happen' - if that were the case there would be an exception/error, instead of a test --- refactor-this/helper.rb | 43 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index 92b233e..92e3155 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -28,39 +28,24 @@ def display_huge_photo(profile, html = {}, options = {}, link = true) end def display_photo(profile, size, html = {}, options = {}, link = true) - return image_tag("wrench.png") unless profile # this should not happen + return image_tag("wrench.png") unless profile show_default_image = !(options[:show_default] == false) - html.reverse_merge!(:class => 'thumbnail', :size => size, :title => "Link to #{profile.name}") - - if profile && profile.user - if profile.has_valid_photo? - if link - return link_to(image_tag(url_for_file_column("user", "photo", size), html), profile_path(profile) ) - else - return image_tag(url_for_file_column("user", "photo", size), html) - end - else - show_default_image ? default_photo(profile, size, {}, link) : 'NO DEFAULT' + html.reverse_merge!(:class => 'thumbnail', :size => size, :title => "Link to #{profile.name}") + + if profile.has_valid_photo? + imagefile = url_for_file_column("user", "photo", size) + else + if show_default_image && profile.user + size = '190x119' if profile.user.rep? + html = {} + elsif profile.user + return 'NO DEFAULT' end - else - link_to(image_tag("user#{size}.jpg", html), profile_path(profile)) + imagefile = "user#{size}.jpg" end - end - def default_photo(profile, size, html={}, link = true) - if link - if profile.user.rep? - link_to(image_tag("user190x119.jpg", html), profile_path(profile) ) - else - link_to(image_tag("user#{size}.jpg", html), profile_path(profile) ) - end - else - if profile.user.rep? - image_tag("user190x119.jpg", html) - else - image_tag("user#{size}.jpg", html) - end - end + img = image_tag(imagefile, html) + return link ? link_to(img, profile_path(profile)) : img end end \ No newline at end of file From 09579b9c869400dbeaeb0da571e20faad5b09f64 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 23:16:01 -0700 Subject: [PATCH 09/20] Add tests for display_X_photo methods, where X = small, medium, large, or huge * only testing the 'regular' user case so far --- refactor-this/helper_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 0c592dc..9a917f4 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -117,6 +117,22 @@ end end end + + # test the display_X_photo methods + {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| + describe "display_#{name}_photo" do + before do + args = [@profile, size, {}, {}] + args << true if /large|huge/.match(name.to_s) + @helper.stub!(:display_photo).with(*args).and_return("photo") + @user.stub!(:rep?).and_return(false) + end + it "should return a #{name} photo" do + @helper.send("display_#{name}_photo", @profile, {}, {}).should == "photo" + end + end + end + end describe "no user, but requesting a link" do before(:each) do @@ -128,5 +144,8 @@ end end end + + + end end \ No newline at end of file From 28dfe12f51f3e79ce00e700d6af36de83c4a261d Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 23:50:29 -0700 Subject: [PATCH 10/20] Remove the individual display_X_photo methods and declare them using a loop * restructure the test code so the test strings are more consistent * combined 'image_size' method in to new method * removed static "foo" method that seemed useless --- refactor-this/helper.rb | 36 ++++++++++-------------------------- refactor-this/helper_spec.rb | 36 ++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 44 deletions(-) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index 92e3155..bc8f308 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -1,32 +1,16 @@ class Helper - def self.foo - "foo" - end - - def image_size(profile, non_rep_size) - if profile.user.rep? - '190x114' - else - non_rep_size + + # Define methods for display_X_photo, where X can be small, medium, large, or huge + {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| + send :define_method, "display_#{name}_photo" do |*args| + profile = args[0] + size '190x119' if profile.user && profile.user.rep? + args = [profile, size, args[1], args[2]] + args << true if /large|huge/.match(name.to_s) + display_photo(*args) end end - - def display_small_photo(profile, html = {}, options = {}) - display_photo(profile, image_size(profile, "32x32"), html, options) - end - - def display_medium_photo(profile, html = {}, options = {}) - display_photo(profile, image_size(profile, "48x48"), html, options) - end - - def display_large_photo(profile, html = {}, options = {}, link = true) - display_photo(profile, image_size(profile, "64x64"), html, options, link) - end - - def display_huge_photo(profile, html = {}, options = {}, link = true) - display_photo(profile, image_size(profile, "200x200"), html, options, link) - end - + def display_photo(profile, size, html = {}, options = {}, link = true) return image_tag("wrench.png") unless profile diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 9a917f4..88f74e8 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -117,22 +117,6 @@ end end end - - # test the display_X_photo methods - {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| - describe "display_#{name}_photo" do - before do - args = [@profile, size, {}, {}] - args << true if /large|huge/.match(name.to_s) - @helper.stub!(:display_photo).with(*args).and_return("photo") - @user.stub!(:rep?).and_return(false) - end - it "should return a #{name} photo" do - @helper.send("display_#{name}_photo", @profile, {}, {}).should == "photo" - end - end - end - end describe "no user, but requesting a link" do before(:each) do @@ -144,8 +128,24 @@ end end end + end - - + # test the display_X_photo methods + {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| + describe "display_#{name}_photo" do + before do + @profile = UserProfile.new + @user = User.new + @profile.user = @user + + args = [@profile, size, {}, {}] + args << true if /large|huge/.match(name.to_s) + @helper.stub!(:display_photo).with(*args).and_return("photo") + @user.stub!(:rep?).and_return(false) + end + it "should return a #{name} photo" do + @helper.send("display_#{name}_photo", @profile, {}, {}).should == "photo" + end + end end end \ No newline at end of file From 173cdb4b0a2da26c0159ce7e48bbe2b2dd3869ae Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 23:53:44 -0700 Subject: [PATCH 11/20] Removed 'profile.rb' - wasn't being used --- refactor-this/profile.rb | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 refactor-this/profile.rb diff --git a/refactor-this/profile.rb b/refactor-this/profile.rb deleted file mode 100644 index b7525df..0000000 --- a/refactor-this/profile.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Profile - attr_accessor :photo -end \ No newline at end of file From 51bc597b1fdc1aa4b72cc539edd5fc4839a71359 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Sun, 16 Jan 2011 23:58:34 -0700 Subject: [PATCH 12/20] Added missing profile_path method and put in FIXME; missing test to define behavior --- refactor-this/helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index bc8f308..d642fc0 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -1,5 +1,10 @@ class Helper + def profile_path(profile) + # FIXME: figure what this should actually be + "/path/to/profiles/#{profile.name}" + end + # Define methods for display_X_photo, where X can be small, medium, large, or huge {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| send :define_method, "display_#{name}_photo" do |*args| From 816c3348a3b8401118cf4e4dd7d0cb0f6b17151f Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 00:25:56 -0700 Subject: [PATCH 13/20] Added 'rails-commits.rb' script for Github challenge Get the commits for Ruby on Rails from Github using the JSON API and print the results in HTML format using and ERB template. --- github-challenge/rails-commits.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 github-challenge/rails-commits.rb diff --git a/github-challenge/rails-commits.rb b/github-challenge/rails-commits.rb new file mode 100644 index 0000000..df76105 --- /dev/null +++ b/github-challenge/rails-commits.rb @@ -0,0 +1,24 @@ +require 'net/http' +require 'uri' +require 'rubygems' +require 'json' +require 'erb' + +# REST URI for Ruby on Rails Github repository most recent commits +url = "http://github.com/api/v2/json/commits/list/rails/rails/master"; + +# Get the commits from the URL using JSON and group them by author +data = JSON.parse(Net::HTTP.get(URI.parse(url)))['commits'].group_by { |commit| commit['author'] } + +# Print the HTML using the embedded ERB template +puts ERB.new(DATA.read).result(binding) + +__END__ +<% data.each do |author, commits| %> +

<%= author['name']%> (<%= author['email'] %>)

+
    + <% commits.each do |commit| %> +
  • <%= commit['id'] %>
    <%= commit['message'] %>
  • + <% end %> +
+<% end %> \ No newline at end of file From 4f0b5d564e256398b9c50296bc12863a038b57ec Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 00:32:00 -0700 Subject: [PATCH 14/20] Added resume in PDF format to 'resume' directory --- resume/Matt_Kopala_resume.pdf | Bin 0 -> 20805 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 resume/Matt_Kopala_resume.pdf diff --git a/resume/Matt_Kopala_resume.pdf b/resume/Matt_Kopala_resume.pdf new file mode 100755 index 0000000000000000000000000000000000000000..0b0133000d2cb22a28bdf690b8d8ee84e624092f GIT binary patch literal 20805 zcmagFLwGI>53XC=TGgs;+qP}HZ*AMQZQHhO+cs9azkgqQb_QpZ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rk{sb(?lBWPY++ zc&=}JGV{jfw|;X`7N45g_vofeH_g6!@$Sg|mU8dQ=J3pc<)8WV!j{(-aHqZQ^~(0Y z?_K=M>o>n&ntkx-!rF%p#fNWv`LegAuZ{f3zUAF(He9{I+O@AE_1ojIyFP#DkAGVk zI{fbouibOW@wV0qZJChXN+>AtZfnKUS;A$Ee{96{>p2^ZGQ@jn zMyUE>4FXAJuvGL&5Sk4F64g-+bIg@gb72ZQY7U+tL2MMT;xs70@Yo+6w{q8G=IK&?5GMEca5G%g>P)bn`^nF^^n$^;ee z&a&xX8zdSSf)?bkVdy1Ww;4g=IqCjXmYZ_i9&tN8vL@W0SYru6`gFUXGS?P7Lo3D*9 zkE90N<7EUnBqkEIzHV%3rKD;T*g;u5rWfPB_xA4hAw3uO4NECLRqDp$`if}_4^6Mk zXwws#lJhN1FtMd7w1Y8QQA=!|o>OBZY-{mF-RXheMTDRdtrSWHST?9qFp74x68BM- zD8K~G`4A;>CgQ%4)F5(96B@3tI0H&RU(Og)Q10FdtP!AE~ny?Euv&pqT|u zAK`=m&$$yN!5m93Il5UyWMVaImYujy460dGR52@t!ZIrem}hyoSVhUJayA?iRVnDs zRPt!pG!;C6xq>iP48SPV(96bXbwF|LV(p&b2q3LKNO6aFRD z=XC@VED!ONGdv#^m8cYA zc{$4SF|LIYG6q1hM4;QrKuIXhCbv2nC|!|2l#VA*fDB3Qy|!pmTJcJ3) Date: Mon, 17 Jan 2011 00:42:26 -0700 Subject: [PATCH 15/20] Added a PHP version of the Github script as well --- github-challenge/rails-commits.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 github-challenge/rails-commits.php diff --git a/github-challenge/rails-commits.php b/github-challenge/rails-commits.php new file mode 100644 index 0000000..fb90d6e --- /dev/null +++ b/github-challenge/rails-commits.php @@ -0,0 +1,18 @@ +commits as $commit) { + $data[$commit->author->email][] = $commit; + } + ksort($data); +?> + $commits): ?> +

author->name . " (" . $email . ")"?>

+
    + +
  • id ?>
    message ?>
  • + +
+ + \ No newline at end of file From 43614468385906c761824c3193404f9e4ae5fc2c Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 00:42:46 -0700 Subject: [PATCH 16/20] Added a README file for the github challenge directory --- github-challenge/README | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 github-challenge/README diff --git a/github-challenge/README b/github-challenge/README new file mode 100644 index 0000000..5ff171e --- /dev/null +++ b/github-challenge/README @@ -0,0 +1,15 @@ +This directory contains script for fetching the most recent Ruby on Rails commits from Github. + +Ruby: + + Usage: ruby rails-commits.rb + Prerequisites: + - gem install json + +PHP: + + Usage: php rails-commits.php + Prerequisites: + - json extension installed & enabled + - short tags enabled + From 4750faa02c3f660efaeaad759d8551bd79830d4c Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 00:48:44 -0700 Subject: [PATCH 17/20] Minor tweaks to the describe strings in 'helper_spec.rb' --- refactor-this/helper_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 88f74e8..0be7473 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -34,7 +34,7 @@ @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end - describe "and user" do + describe "user" do before do @user = User.new @profile.user = @user @@ -42,7 +42,7 @@ @profile.stub!(:has_valid_photo?).and_return(true) @helper.stub!(:url_for_file_column).with("user", "photo", "100x100").and_return("imagefile") end - describe "and photo" do + describe "and photo," do before do @photo = Photo.new @user.photo = @photo @@ -68,7 +68,7 @@ end - describe "without a photo" do + describe "without a photo," do before(:each) do @profile.stub!(:has_valid_photo?).and_return(false) end @@ -94,7 +94,7 @@ end end - describe "and we don't want to display the default" do + describe "we don't want to display the default," do before(:each) do @options = {:show_default => false} end @@ -102,7 +102,7 @@ before(:each) do @user.stub!(:rep?).and_return(true) end - it "return a default link" do + it "return 'NO DEFAULT'" do @helper.display_photo(@profile, "100x100", {}, @options, true).should == "NO DEFAULT" end end @@ -111,7 +111,7 @@ before(:each) do @user.stub!(:rep?).and_return(false) end - it "return a default link" do + it "return 'NO DEFAULT'" do @helper.display_photo(@profile, "100x100", {}, @options, true).should == "NO DEFAULT" end end From cec360ee36e89ca16adf5f4a64048527b658642d Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 00:56:32 -0700 Subject: [PATCH 18/20] Add four extra tests for the display_X_photo methods, for the 'rep' user case * fixed bug with missing = in code --- refactor-this/helper.rb | 2 +- refactor-this/helper_spec.rb | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/refactor-this/helper.rb b/refactor-this/helper.rb index d642fc0..7b2edd0 100644 --- a/refactor-this/helper.rb +++ b/refactor-this/helper.rb @@ -9,7 +9,7 @@ def profile_path(profile) {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| send :define_method, "display_#{name}_photo" do |*args| profile = args[0] - size '190x119' if profile.user && profile.user.rep? + size = '190x119' if profile.user && profile.user.rep? args = [profile, size, args[1], args[2]] args << true if /large|huge/.match(name.to_s) display_photo(*args) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 0be7473..93e3dcd 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -137,15 +137,29 @@ @profile = UserProfile.new @user = User.new @profile.user = @user - - args = [@profile, size, {}, {}] - args << true if /large|huge/.match(name.to_s) - @helper.stub!(:display_photo).with(*args).and_return("photo") - @user.stub!(:rep?).and_return(false) end - it "should return a #{name} photo" do - @helper.send("display_#{name}_photo", @profile, {}, {}).should == "photo" - end + describe "With a regular user" do + before do + args = [@profile, size, {}, {}] + args << true if /large|huge/.match(name.to_s) + @helper.stub!(:display_photo).with(*args).and_return("photo") + @user.stub!(:rep?).and_return(false) + end + it "return a #{name} photo" do + @helper.send("display_#{name}_photo", @profile, {}, {}).should == "photo" + end + end + describe "With a rep user" do + before do + args = [@profile, "190x119", {}, {}] + args << true if /large|huge/.match(name.to_s) + @helper.stub!(:display_photo).with(*args).and_return("photo") + @user.stub!(:rep?).and_return(true) + end + it "return a fixed-size photo" do + @helper.send("display_#{name}_photo", @profile, {}, {}).should == "photo" + end + end end end end \ No newline at end of file From c43ca3520171ee004176e6f09f09abaedc3e1567 Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 01:01:33 -0700 Subject: [PATCH 19/20] Removed unnecessary 'require' statements from 'helper_spec.rb' * Not needed for running spec from the command line --- refactor-this/helper_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 93e3dcd..5018bd6 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -1,9 +1,5 @@ -require 'rubygems' require 'factory_girl' require 'factories' -require 'spec' -require 'spec/autorun' -require 'redgreen' require 'user_profile' require 'helper' require 'user' From db8f03e7b64200c88c53417f84b26493d1e29ebc Mon Sep 17 00:00:00 2001 From: Matt Kopala Date: Mon, 17 Jan 2011 09:57:29 -0700 Subject: [PATCH 20/20] Replaced object creation in tests with fixtures using Factory_girl * Not that important or useful right now, but README seemed to indicate it was desired --- refactor-this/factories.rb | 4 ++++ refactor-this/helper_spec.rb | 11 +++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/refactor-this/factories.rb b/refactor-this/factories.rb index 9685df6..9ec3a0c 100644 --- a/refactor-this/factories.rb +++ b/refactor-this/factories.rb @@ -7,6 +7,10 @@ u.email Factory.next(:email) end +Factory.define(:user_profile) do |p| + p.name "Clayton" +end + Factory.define(:photo) do |p| end \ No newline at end of file diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb index 5018bd6..f9efccd 100644 --- a/refactor-this/helper_spec.rb +++ b/refactor-this/helper_spec.rb @@ -24,15 +24,14 @@ describe "With a profile," do before do - @profile = UserProfile.new - @profile.name = "Clayton" + @profile = Factory.build(:user_profile) @html = {:class => 'thumbnail', :size => "100x100", :title => "Link to #{@profile.name}"} @helper.stub!(:profile_path).with(@profile).and_return("profile_path") end describe "user" do before do - @user = User.new + @user = Factory.build(:user) @profile.user = @user @profile.stub!(:has_valid_photo?).and_return(true) @@ -40,7 +39,7 @@ end describe "and photo," do before do - @photo = Photo.new + @photo = Factory.build(:photo) @user.photo = @photo end describe "requesting a link" do @@ -130,8 +129,8 @@ {:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size| describe "display_#{name}_photo" do before do - @profile = UserProfile.new - @user = User.new + @profile = Factory.build(:user_profile) + @user = Factory.build(:user) @profile.user = @user end describe "With a regular user" do