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
+
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);
+?>
+ foreach ($data as $email => $commits): ?>
+
= $commits[0]->author->name . " (" . $email . ")"?>
+
+ foreach ($commits as $commit): ?>
+ - = $commit->id ?>
= $commit->message ?>
+ endforeach ?>
+
+
+ endforeach ?>
\ No newline at end of file
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
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.rb b/refactor-this/helper.rb
index 6ef273b..7b2edd0 100644
--- a/refactor-this/helper.rb
+++ b/refactor-this/helper.rb
@@ -1,67 +1,40 @@
class Helper
- def self.foo
- "foo"
- end
-
- def image_size(profile, non_rep_size)
- if profile.user.rep?
- '190x114'
- else
- non_rep_size
+
+ 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|
+ 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 # 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.user && profile.user.photo && File.exists?(profile.user.photo)
- @user = profile.user
- 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) : ''
+ 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
+ imagefile = "user#{size}.jpg"
end
- show_default_image ? default_photo(profile, size, {}, link) : ''
- 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
diff --git a/refactor-this/helper_spec.rb b/refactor-this/helper_spec.rb
index b82e40e..f9efccd 100644
--- a/refactor-this/helper_spec.rb
+++ b/refactor-this/helper_spec.rb
@@ -1,119 +1,160 @@
-require 'rubygems'
require 'factory_girl'
require 'factories'
-require 'spec'
-require 'spec/autorun'
-require 'redgreen'
require 'user_profile'
require 'helper'
require 'user'
require 'photo'
+require 'active_support/core_ext/hash/reverse_merge'
describe "Helper" do
before(:each) do
@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"
- end
-
- describe "With a profile, user and photo 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 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"
- end
- end
-
- describe "Without a user, but requesting a link" do
- before(:each) do
- @profile = UserProfile.new
- @profile.name = "Clayton"
+ describe "If the profile is not set" do
+ before do
+ @helper.stub!(:image_tag) do |img|
+ img
+ end
end
- it "return a default" do
- @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100"
+ it "return the wrench" do
+ @helper.display_photo(nil, "100x100", {}, {}, true).should == "wrench.png"
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
+ describe "With a profile," do
+ before do
+ @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 = Factory.build(:user)
+ @profile.user = @user
+
+ @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
+ before do
+ @photo = Factory.build(:photo)
+ @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 "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 "With a regular user" do
+ 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"
+ end
+ end
+
+ describe "we don't want to display the default," do
+ before(:each) do
+ @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 'NO DEFAULT'" do
+ @helper.display_photo(@profile, "100x100", {}, @options, 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 'NO DEFAULT'" do
+ @helper.display_photo(@profile, "100x100", {}, @options, true).should == "NO DEFAULT"
+ end
+ end
+ end
+ end
+ end
+ describe "no user, but requesting a link" do
before(:each) do
- @user.stub!(:rep?).and_return(false)
+ @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
- 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
-
+ # 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 = Factory.build(:user_profile)
+ @user = Factory.build(:user)
+ @profile.user = @user
end
-
describe "With a regular user" do
- before(:each) 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 default link" do
- @helper.display_photo(@profile, "100x100", {}, {}, true).should == "default link 100x100"
+ 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
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
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
diff --git a/resume/Matt_Kopala_resume.pdf b/resume/Matt_Kopala_resume.pdf
new file mode 100755
index 0000000..0b01330
Binary files /dev/null and b/resume/Matt_Kopala_resume.pdf differ