Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
sobrinho committed Jan 24, 2010
1 parent 4d9569f commit 688bf96
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 28 deletions.
9 changes: 2 additions & 7 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module ApplicationHelper
def gravatar_image_tag email, options = {}
def gravatar_image_tag email
email = Digest::MD5.hexdigest(email)
default = CGI.escape(request.protocol + request.host_with_port + image_path('gravatar.jpg'))

image_tag "http://www.gravatar.com/avatar/#{email}?size=48&default=#{default}", options
end

def link_to_with_active name, options
link_to name, options, :class => ('active' if current_page? options)
image_tag "http://www.gravatar.com/avatar/#{email}?size=48&default=#{default}", :alt => 'Gravatar'
end
end

13 changes: 5 additions & 8 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ class User < ActiveRecord::Base

# Fetch user projects from Github
def fetch_projects!
self.projects.destroy_all
projects.destroy_all

returning true do
if self.github?
result = YAML.load open("http://github.com/api/v2/yaml/repos/show/#{github}/")
if github?
result = YAML.load open("http://github.com/api/v2/yaml/repos/show/#{github}/")

result['repositories'].each do |repository|
self.projects.create! :name => repository[:name], :description => repository[:description]
end
result['repositories'].each do |repository|
projects.create! :name => repository[:name], :description => repository[:description]
end
end
rescue OpenURI::HTTPError # user not found, ignore
false
end

after_create :deliver_signup_confirmation
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- @users.each do |user|
%li{ :id => dom_id(user) }
%span.gravatar
= link_to gravatar_image_tag(user.email, :alt => 'Avatar'), user_path(user)
= link_to gravatar_image_tag(user.email), user_path(user)
%h3.name
= link_to h(user), user_path(user)
%span.github
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- @users.each do |user|
%li
%span.gravatar
= link_to gravatar_image_tag(user.email, :alt => 'Avatar'), user_path(user)
= link_to gravatar_image_tag(user.email), user_path(user)
%span.name
= link_to h(user.name), user_path(user)
%span.city
Expand Down
12 changes: 1 addition & 11 deletions spec/blueprints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
User.blueprint do
name 'Gabriel Sobrinho'
email '[email protected]'
github 'sobrinho'
city 'Belo Horizonte'
password { '123456' }
password_salt { Authlogic::Random.hex_token }
crypted_password { Authlogic::CryptoProviders::Sha512.encrypt(password + password_salt) }
persistence_token { Authlogic::Random.hex_token }
perishable_token { Authlogic::Random.friendly_token }
end

Project.blueprint do
user { User.make }
name 'Example project'
description 'An example project'
end

Meeting.blueprint do
name 'Meeting example'
description 'An example of meeting'
end
7 changes: 7 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe ApplicationHelper do
it 'gravatar_image_tag should return a gravatar image' do
helper.gravatar_image_tag('[email protected]').should have_tag 'img[src^=http://www.gravatar.com/avatar/][alt=Gravatar]'
end
end
7 changes: 7 additions & 0 deletions spec/helpers/home_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe HomeHelper do
it 'link_to_take should return a Google Maps link' do
helper.link_to_take.should have_tag 'a[href^=http://maps.google.com/maps]', 'veja o mapa'
end
end
17 changes: 17 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@
subject.name = 'Gabriel Sobrinho'
subject.to_s.should eql 'Gabriel Sobrinho'
end

it 'github_url should return a valid github url' do
subject.github = 'sobrinho'
subject.github_url.should eql 'http://github.com/sobrinho'
end

it 'twitter_url should return a valid twitter url' do
subject.twitter = 'sobrinho'
subject.twitter_url.should eql 'http://twitter.com/sobrinho'
end

it 'fetch_projects! should fetch user projects' do
user = User.make

user.fetch_projects!
user.projects.should have(18).records
end

it 'active! should set active as true' do
user = User.make
Expand Down
182 changes: 182 additions & 0 deletions spec/support/sobrinho.github.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
repositories:
- :description: ActiveRecord e-mail validation for Rails 2.3
:forks: 0
:url: http://github.com/sobrinho/validates_as_email
:homepage: ""
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: validates_as_email
:owner: sobrinho
- :description: Validation of URI (URL) for ActiveRecord
:forks: 0
:url: http://github.com/sobrinho/validates_as_uri
:homepage: ""
:watchers: 1
:fork: false
:private: false
:open_issues: 0
:name: validates_as_uri
:owner: sobrinho
- :description: Validation of CPF for ActiveRecord (Rails >= 2.3)
:forks: 1
:url: http://github.com/sobrinho/validates_as_cpf
:homepage: ""
:watchers: 3
:fork: false
:private: false
:open_issues: 0
:name: validates_as_cpf
:owner: sobrinho
- :description: Validation of CNPJ for ActiveRecord (Rails >= 2.3)
:forks: 1
:url: http://github.com/sobrinho/validates_as_cnpj
:homepage: ""
:watchers: 2
:fork: false
:private: false
:open_issues: 0
:name: validates_as_cnpj
:owner: sobrinho
- :description: Replaces <select> tags with a full-HTML, RESTful JavaScript record browser (Rails plugin)
:forks: 0
:url: http://github.com/sobrinho/recordselect
:homepage: http://code.google.com/p/recordselect
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: recordselect
:owner: sobrinho
- :description: A PHP MVC RESTful framework
:forks: 0
:url: http://github.com/sobrinho/corephp
:homepage: http://www.corephp.org/
:watchers: 1
:fork: false
:private: false
:open_issues: 0
:name: corephp
:owner: sobrinho
- :description: A simple Rails wrapper for the PrinceXML PDF generation library.
:forks: 0
:url: http://github.com/sobrinho/princely
:homepage: http://www.mbleigh.com/plugins/princely-rails-prince-xml-wrapper
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: princely
:owner: sobrinho
- :description: This plugins create a form_ui and list_ui helpers for ActiveScaffold to use columns like enum
:forks: 0
:url: http://github.com/sobrinho/as_enum_column
:homepage: ""
:watchers: 4
:fork: false
:private: false
:open_issues: 0
:name: as_enum_column
:owner: sobrinho
- :description: Fancy pants drag-drop sortable lists for ActiveScaffold
:forks: 0
:url: http://github.com/sobrinho/active_scaffold_sortable
:homepage: http://tim.theenchanter.com/2008/05/activescaffoldsortable-updated-with.html
:watchers: 2
:fork: true
:private: false
:open_issues: 0
:name: active_scaffold_sortable
:owner: sobrinho
- :description: ActsAsTree plugin
:forks: 0
:url: http://github.com/sobrinho/acts_as_tree
:homepage: http://rubyonrails.org
:watchers: 2
:fork: true
:private: false
:open_issues: 0
:name: acts_as_tree
:owner: sobrinho
- :description: RSpec Mate is a plugin to show results of specs like Textmate in Gedit
:forks: 0
:url: http://github.com/sobrinho/rspec_mate
:homepage: ""
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: rspec_mate
:owner: sobrinho
- :description: A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
:forks: 0
:url: http://github.com/sobrinho/acts-as-taggable-on
:homepage: http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: acts-as-taggable-on
:owner: sobrinho
- :description: Demo app using InheritedResources + HAML + Formtastic
:forks: 0
:url: http://github.com/sobrinho/2railsmg
:homepage: ""
:watchers: 1
:fork: false
:private: false
:open_issues: 0
:name: 2railsmg
:owner: sobrinho
- :description: Repository for collecting Locale data for Ruby on Rails I18n as well as other interesting, Rails related I18n stuff
:forks: 0
:url: http://github.com/sobrinho/rails-i18n
:homepage: http://rails-i18n.org
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: rails-i18n
:owner: sobrinho
- :description: Blog used in spartaonrails.com
:forks: 0
:url: http://github.com/sobrinho/spartaonrails
:homepage: http://spartaonrails.com/
:watchers: 1
:fork: false
:private: false
:open_issues: 0
:name: spartaonrails
:owner: sobrinho
- :description: has_breadcrumbs is a simple plugin that adds a `breadcrumb` object into controllers and views.
:forks: 0
:url: http://github.com/sobrinho/has_breadcrumbs
:homepage: http://github.com/fnando/has_breadcrumbs
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: has_breadcrumbs
:owner: sobrinho
- :description: "railsmg website "
:forks: 0
:url: http://github.com/sobrinho/railsmg
:homepage: ""
:watchers: 1
:fork: true
:private: false
:open_issues: 0
:name: railsmg
:owner: sobrinho
- :description: This plugin makes ActiveRecord models rateable through a polymorphic association
:forks: 0
:url: http://github.com/sobrinho/acts_as_rateable
:homepage: ""
:watchers: 1
:fork: false
:private: false
:open_issues: 0
:name: acts_as_rateable
:owner: sobrinho
6 changes: 6 additions & 0 deletions spec/support/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
User.class_eval do
# User#fetch_projects! is called on save and we cant stub Kernel#open method
def open *args
File.open("#{Rails.root}/spec/support/sobrinho.github.yaml")
end
end

0 comments on commit 688bf96

Please sign in to comment.