Permalink
Browse files

Merge branch 'release/0.1.3'

  • Loading branch information...
2 parents cd887d8 + cdf366d commit c8b0991df6aece7c43000d3e74879846d9b44726 @jeffkreeftmeijer jeffkreeftmeijer committed Jun 22, 2011
View
@@ -20,7 +20,6 @@ gem 'mongoid_slug', :require => 'mongoid/slug'
gem 'omniauth'
gem 'gravtastic'
-gem 'httparty'
gem 'gust', :path => 'vendor/gems/gust'
View
@@ -66,7 +66,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.1.1)
- crack (0.1.8)
daemons (1.1.3)
database_cleaner (0.6.4)
diff-lcs (1.1.2)
@@ -92,8 +91,6 @@ GEM
hoptoad_notifier (2.4.11)
activesupport
builder
- httparty (0.7.8)
- crack (= 0.1.8)
i18n (0.6.0)
jquery-rails (1.0.7)
railties (~> 3.0)
@@ -260,7 +257,6 @@ DEPENDENCIES
gust!
haml
hoptoad_notifier
- httparty
jquery-rails
json
kramdown
@@ -50,7 +50,7 @@ img.gravatar
border: 1px solid #ddd
vertical-align: middle
-p
+p, img.contestant
margin: 10px 0
form
View
@@ -1,19 +1,11 @@
-require "net/https"
-require "uri"
+require "#{Rails.root}/lib/gist"
class GistValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- uri = URI.parse("https://api.github.com/gists/#{value}")
- http = Net::HTTP.new(uri.host, uri.port)
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ gist = Gist.fetch(value)
- request = Net::HTTP::Get.new(uri.request_uri)
-
- response = http.request(request)
-
- return record.errors[attribute] << "is not valid" unless response.code == '200'
- record.errors[attribute] << "is not yours" unless record.user.github_id == MultiJson.decode(response.body)['user']['id']
+ return record.errors[attribute] << "is not valid" unless gist.code == 200
+ record.errors[attribute] << "is not yours" unless record.user.github_id == gist['user']['id']
end
end
@@ -48,7 +40,7 @@ def score
def get_files_from_gist
return {} unless gist_id
- HTTParty.get("https://api.github.com/gists/#{gist_id}")['files']
+ Gist.fetch(gist_id)['files']
end
def files
@@ -2,6 +2,12 @@
= raw Kramdown::Document.new(@contest.description).to_html
+- if @contest.open? && @contest.entries.any?
+
+ %h3 Contestants
+ - @contest.entries.map(&:user).each do |contestant|
+ = image_tag(contestant.gravatar_url, :class => 'gravatar contestant', :alt => contestant.login, :title => contestant.login)
+
- unless @contest.open?
%h3 Entries
View
@@ -0,0 +1,29 @@
+require "net/https"
+require "uri"
+require 'multi_json'
+
+class Gist
+ attr_accessor :code, :body
+
+ def initialize(code, body)
+ @code = code.to_i
+ @body = body
+ end
+
+ def self.fetch(id)
+ uri = URI.parse("https://api.github.com/gists/#{id}")
+
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+
+ request = Net::HTTP::Get.new(uri.request_uri)
+ response = http.request(request)
+
+ new(response.code, response.body)
+ end
+
+ def [](attribute)
+ MultiJson.decode(body)[attribute]
+ end
+end
@@ -29,6 +29,14 @@
end
+share_examples_for 'a contest without a contestants box' do
+
+ scenario 'do not see the contestant box' do
+ page.should have_no_content 'Contestants'
+ end
+
+end
+
feature 'Contests' do
context 'on a contest page' do
@@ -87,6 +95,23 @@
page.should have_link 'Enter'
end
+ scenario 'see the contestant box' do
+ within'#main' do
+ body.should include 'http://gravatar.com/avatar/1dae832a3c5ae2702f34ed50a40010e8.png'
+ end
+ end
+
+ context 'on a contest page that has no entries' do
+
+ background do
+ contest = Fabricate(:contest, :starting_on => Date.yesterday.to_time)
+ visit "/contests/#{contest.slug}"
+ end
+
+ it_should_behave_like 'a contest without a contestants box'
+
+ end
+
end
context 'when the contest is open for voting' do
@@ -105,6 +130,8 @@
it_should_behave_like 'a contest closed for further entries'
+ it_should_behave_like 'a contest without a contestants box'
+
scenario 'see the voting controls' do
(1..5).to_a.each { |i| page.should have_field i.to_s }
page.should have_button 'Submit your votes'
@@ -130,6 +157,8 @@
it_should_behave_like 'a contest closed for further entries'
+ it_should_behave_like 'a contest without a contestants box'
+
scenario 'do not see the voting controls' do
(1..5).to_a.each { |i| page.should have_no_field i.to_s }
page.should have_no_button 'Submit your votes'
@@ -0,0 +1,36 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: https://api.github.com:443/gists/12345
+ body: !!null
+ headers: !!null
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ server:
+ - nginx/0.7.67
+ date:
+ - Tue, 21 Jun 2011 07:59:50 GMT
+ content-type:
+ - application/json
+ status:
+ - 200 OK
+ x-ratelimit-limit:
+ - '5000'
+ x-ratelimit-remaining:
+ - '4999'
+ content-length:
+ - '1782'
+ body: ! '{"git_pull_url":"git://gist.github.com/12345.git","url":"https://api.github.com/gists/12345","forks":[],"git_push_url":"git@gist.github.com:12345.git","files":{"gistfile1.txt":{"filename":"gistfile1.txt","content":"~/testbed/dm_test
+ $ rake dm:db:database_yaml\r\n(in /Users/jdempsey/testbed/dm_test)\r\n/Users/jdempsey/testbed/dm_test/config/init.rb:1:
+ warning: already initialized constant KCODE\r\n ~ Loaded DEVELOPMENT Environment...\r\n
+ ~ loading gem ''merb_datamapper'' ...\r\n ~ loading gem ''dm-core'' ...\r\n
+ ~ loading gem ''merb_datamapper'' ...\r\n ~ Merb::Orms::DataMapper::Connect
+ block.\r\n ~ No database.yml file found in /Users/jdempsey/testbed/dm_test/config,
+ assuming database connection(s) established in the environment file in /Users/jdempsey/testbed/dm_test/config/environments\r\n
+ ~ Checking if we need to use DataMapper sessions\r\n ~ Merb::Orms::DataMapper::Connect
+ complete\r\n ~ Compiling routes...\r\n ~ Starting Merb server listening at 0.0.0.0:4000\r\n","size":734,"raw_url":"https://gist.github.com/raw/12345/1380168c2b5ea8616f09eeb50e8c3417e24453a8/gistfile1.txt"}},"html_url":"https://gist.github.com/12345","user":{"url":"https://api.github.com/users/jackdempsey","avatar_url":"https://secure.gravatar.com/avatar/1ccb5123d1af92e24b32cec62abcf9a8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jackdempsey","id":479},"public":true,"comments":0,"description":null,"history":[{"version":"a714a381787af0f56e86d12be63e0336bf0eea19","url":"https://api.github.com/gists/12345/a714a381787af0f56e86d12be63e0336bf0eea19","user":null,"change_status":{"deletions":0,"additions":13,"total":13},"committed_at":"2008-09-23T17:13:04Z"}],"id":"12345","updated_at":"2009-10-14T11:53:04Z","created_at":"2008-09-23T17:13:04Z"}'
+ http_version: '1.1'
View
@@ -0,0 +1,62 @@
+require 'spec_helper'
+require File.expand_path('../../../lib/gist', __FILE__)
+
+describe Gist do
+
+ context 'after initializing with valid data' do
+
+ before { @gist = Gist.new("200", '{"foo": "bar"}') }
+
+ context '.code' do
+
+ subject { @gist.code }
+
+ it { should == 200 }
+
+ end
+
+ context '.body' do
+
+ subject { @gist.body }
+
+ it { should == '{"foo": "bar"}' }
+
+ end
+
+ context '.["foo"]' do
+
+ subject { @gist['foo'] }
+
+ it { should == "bar" }
+
+ end
+
+ end
+
+ context '.fetch' do
+
+ subject{ VCR.use_cassette('random_gist') { Gist.fetch('12345') } }
+
+ it { should be_an_instance_of Gist }
+
+ context 'the response code' do
+
+ subject{ VCR.use_cassette('random_gist') { Gist.fetch('12345').code } }
+
+ it { should == 200 }
+
+ end
+
+ context 'body' do
+
+ subject{ VCR.use_cassette('random_gist') { Gist.fetch('12345').body } }
+
+ it 'should contain the raw response body' do
+ should == "{\"git_pull_url\":\"git://gist.github.com/12345.git\",\"url\":\"https://api.github.com/gists/12345\",\"forks\":[],\"git_push_url\":\"git@gist.github.com:12345.git\",\"files\":{\"gistfile1.txt\":{\"filename\":\"gistfile1.txt\",\"content\":\"~/testbed/dm_test $ rake dm:db:database_yaml\\r\\n(in /Users/jdempsey/testbed/dm_test)\\r\\n/Users/jdempsey/testbed/dm_test/config/init.rb:1: warning: already initialized constant KCODE\\r\\n ~ Loaded DEVELOPMENT Environment...\\r\\n ~ loading gem 'merb_datamapper' ...\\r\\n ~ loading gem 'dm-core' ...\\r\\n ~ loading gem 'merb_datamapper' ...\\r\\n ~ Merb::Orms::DataMapper::Connect block.\\r\\n ~ No database.yml file found in /Users/jdempsey/testbed/dm_test/config, assuming database connection(s) established in the environment file in /Users/jdempsey/testbed/dm_test/config/environments\\r\\n ~ Checking if we need to use DataMapper sessions\\r\\n ~ Merb::Orms::DataMapper::Connect complete\\r\\n ~ Compiling routes...\\r\\n ~ Starting Merb server listening at 0.0.0.0:4000\\r\\n\",\"size\":734,\"raw_url\":\"https://gist.github.com/raw/12345/1380168c2b5ea8616f09eeb50e8c3417e24453a8/gistfile1.txt\"}},\"html_url\":\"https://gist.github.com/12345\",\"user\":{\"url\":\"https://api.github.com/users/jackdempsey\",\"avatar_url\":\"https://secure.gravatar.com/avatar/1ccb5123d1af92e24b32cec62abcf9a8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"login\":\"jackdempsey\",\"id\":479},\"public\":true,\"comments\":0,\"description\":null,\"history\":[{\"version\":\"a714a381787af0f56e86d12be63e0336bf0eea19\",\"url\":\"https://api.github.com/gists/12345/a714a381787af0f56e86d12be63e0336bf0eea19\",\"user\":null,\"change_status\":{\"deletions\":0,\"additions\":13,\"total\":13},\"committed_at\":\"2008-09-23T17:13:04Z\"}],\"id\":\"12345\",\"updated_at\":\"2009-10-14T11:53:04Z\",\"created_at\":\"2008-09-23T17:13:04Z\"}"
+ end
+
+ end
+
+ end
+
+end

0 comments on commit c8b0991

Please sign in to comment.