Skip to content
Browse files

Getting specs to pass.

pendings for missing matchers (mostly have_tag)
changes in assigns[] to assign()
changes in rendering
  • Loading branch information...
1 parent 9f6b833 commit f5e3a8d2e1af0cf3f2fae2e1aaf9949a38eeec0c @jschoolcraft committed Jul 12, 2010
View
6 app/models/link.rb
@@ -6,8 +6,8 @@ class Link < ActiveRecord::Base
has_many :tags, :through => :tagged_links
validates_presence_of :url
- # named_scope :today, :conditions => ["links.created_at > ?", Date.today.to_time], :order => "links.created_at desc"
- named_scope :latest, :limit => 10, :order => "links.created_at desc"
+ # scope :today, :conditions => ["links.created_at > ?", Date.today.to_time], :order => "links.created_at desc"
+ scope :latest, :limit => 10, :order => "links.created_at desc"
class << self
def count_bookmarks(above)
self.count(:all, :conditions => ['links.bookmarks > ?', above])
@@ -35,7 +35,7 @@ def can_run_updates?
end
def source_tags=(new_tags)
- self.write_attribute(:source_tags, new_tags.join(','))
+ write_attribute(:source_tags, new_tags.join(','))
end
def source_tags
View
6 app/models/tag.rb
@@ -6,9 +6,9 @@ class Tag < ActiveRecord::Base
validates_presence_of :name
validates_format_of :name, :with => /^[\w\d\.#-]+$/, :on => :create, :message => "is invalid"
- named_scope :ascending, :order => 'tags.name ASC'
- named_scope :top, :order => "tags.taggings_count DESC, tags.name ASC", :limit => 9
- named_scope :recent_taggings, :joins => :taggings, :group => "taggings.tag_id", :order => "taggings.created_at DESC", :limit => 5
+ scope :ascending, :order => 'tags.name ASC'
+ scope :top, :order => "tags.taggings_count DESC, tags.name ASC", :limit => 9
+ scope :recent_taggings, :joins => :taggings, :group => "taggings.tag_id", :order => "taggings.created_at DESC", :limit => 5
def to_s
name
View
2 app/models/tagged_link.rb
@@ -4,7 +4,7 @@ class TaggedLink < ActiveRecord::Base
class << self
def fetch_log(message, indent=0)
- FETCH_LOG.info("#{' ' * indent}#{message}")
+ # FETCH_LOG.info("#{' ' * indent}#{message}")
end
def fetch_links_for_all_tags
View
2 app/models/tagging.rb
@@ -2,5 +2,5 @@ class Tagging < ActiveRecord::Base
belongs_to :user
belongs_to :tag, :counter_cache => true
- named_scope :for_user, lambda { |u| {:conditions => { :user_id => u.id }} }
+ scope :for_user, lambda { |u| {:conditions => { :user_id => u.id }} }
end
View
2 app/views/tags/show.atom.erb
@@ -14,5 +14,5 @@ Atom::Feed.new do |f|
e.content = Atom::Content::Html.new(render(:partial => "link.atom.erb", :object => link, :locals => { :tag => @tag }))
end
end
-end.to_xml
+end.to_xml.html_safe
%>
View
2 app/views/tags/summary.atom.erb
@@ -10,5 +10,5 @@ Atom::Feed.new do |f|
e.updated = @links && @links.first && @links.first.created_at
e.content = Atom::Content::Html.new(render(:partial => 'tag.atom.erb', :object => @tag))
end
-end.to_xml
+end.to_xml.html_safe
%>
View
2 app/views/users/show.atom.erb
@@ -14,5 +14,5 @@ Atom::Feed.new do |f|
e.content = Atom::Content::Html.new(render(:partial => "link.atom.erb", :object => link))
end
end
-end.to_xml
+end.to_xml.html_safe
%>
View
2 app/views/users/summary.atom.erb
@@ -15,5 +15,5 @@ Atom::Feed.new do |f|
end
e.content = Atom::Content::Html.new(content.join)
end
-end.to_xml
+end.to_xml.html_safe
%>
View
7 config/application.rb
@@ -1,13 +1,16 @@
# Put this in config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
+require 'open-uri'
+
+# explicit requires from Gemfile/bundler
require 'Authlogic'
-# require 'open-uri'
+require 'atom'
module Urlagg
class Application < Rails::Application
config.time_zone = 'UTC'
end
end
-# FETCH_LOG = Logger.new(File.open(RAILS_ROOT + '/log/fetch.log', File::WRONLY | File::APPEND | File::CREAT))
+# FETCH_LOG = Logger.new(File.open(Rails.root + '/log/fetch.log', File::WRONLY | File::APPEND | File::CREAT))
View
2 config/routes.rb
@@ -26,7 +26,7 @@
resources :password_resets
resources :taggings
- match 'pages/:id' => 'pages#show'
+ match 'pages/:id' => 'pages#show', :id => 'index'
namespace :admin do
match 'dashboard' => 'dashboard#index', :as => :dashboard
View
8 spec/controllers/tags_controller_spec.rb
@@ -147,9 +147,9 @@ def do_get(options={})
describe "handling GET /show for ATOM" do
before do
- @tag = stub_model(Tag, :links => [])
- Tag.stub!(:find).and_return(@tag)
@links = (1..20).map { |i| mock_model(Link, :url => "http://example-#{i}.com") }
+ @tag = stub_model(Tag, :links => mock("links", :paginate => @link))
+ Tag.stub!(:find).and_return(@tag)
end
def do_get
@@ -168,7 +168,7 @@ def do_get
it "should render the show atom template" do
do_get
- response.should render_template('show.atom.erb')
+ response.should render_template('show')
end
end
@@ -197,7 +197,7 @@ def do_get
it "should render the summary template" do
do_get
- response.should render_template('summary.atom.erb')
+ response.should render_template('summary')
end
end
View
2 spec/controllers/users_controller_spec.rb
@@ -59,7 +59,7 @@ def do_get
it "renders the summary templates" do
do_get
- response.should render_template('summary.atom.erb')
+ response.should render_template('summary')
end
end
View
4 spec/models/link_spec.rb
@@ -45,7 +45,7 @@
describe "updating the bookmark count" do
before(:each) do
@link = Factory.create(:link)
- @json_file = open(RAILS_ROOT + '/spec/fixtures/delicious/urlinfo.json')
+ @json_file = open(File.join(Rails.root, '/spec/fixtures/delicious/urlinfo.json'))
@link.stub!(:open).and_return(@json_file)
end
@@ -131,4 +131,4 @@
Link.needing_bookmarks_updated(50, 1.week.ago, 1).size.should == 1
end
end
-end
+end
View
4 spec/models/notifier_spec.rb
@@ -17,12 +17,12 @@
end
it "should contain the reset password instructions in the mail body" do
- @email.should have_text(/A request to reset your password has been made/)
+ @email.should have_body_text(/A request to reset your password has been made/)
end
it "should contain a link to the password reset link" do
pending "lost access to UrlWriter" do
- @email.should have_text(/#{edit_password_reset_url(@user.perishable_token)}/)
+ @email.should have_body_text(/#{edit_password_reset_url(@user.perishable_token)}/)
end
end
View
6 spec/models/tag_spec.rb
@@ -2,9 +2,9 @@
describe Tag do
should_have_column :taggings_count, :type => :integer
- should_have_named_scope :ascending
- should_have_named_scope :top, :order => "tags.taggings_count DESC, tags.name ASC", :limit => 9
- should_have_named_scope :recent_taggings
+ should_have_scope :ascending
+ should_have_scope :top, :order => "tags.taggings_count DESC, tags.name ASC", :limit => 9
+ should_have_scope :recent_taggings
before(:each) do
@valid_attributes = {
View
8 spec/models/tagged_link_spec.rb
@@ -38,8 +38,8 @@
@tag = Factory.create(:tag, :name => 'gtd')
@tag.tagged_links.stub!(:find_by_link_id).and_return(nil)
- @json_file = open(RAILS_ROOT + '/spec/fixtures/delicious/gtd.json')
- @json = open(RAILS_ROOT + '/spec/fixtures/delicious/gtd.json').read
+ @json_file = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd.json'))
+ @json = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd.json')).read
TaggedLink.stub!(:open).and_return(@json_file)
@@ -113,8 +113,8 @@
@tag = Factory.create(:tag, :name => 'gtd')
@tag.tagged_links.stub!(:find_by_link_id).and_return(nil)
- @json_file = open(RAILS_ROOT + '/spec/fixtures/delicious/gtd-recent.json')
- @json = open(RAILS_ROOT + '/spec/fixtures/delicious/gtd-recent.json').read
+ @json_file = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd-recent.json'))
+ @json = open(File.join(Rails.root, '/spec/fixtures/delicious/gtd-recent.json')).read
TaggedLink.stub!(:open).and_return(@json_file)
View
21 spec/views/tags/_link.atom.erb_spec.rb
@@ -1,6 +1,7 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe '/tags/_link.atom.erb' do
+describe 'tags/_link.atom.erb' do
+ helper(TagsHelper)
before(:each) do
@tag = mock_model(Tag, :name => 'tag-title')
@link = mock_model(Link, :title => "link-title",
@@ -10,23 +11,25 @@
mock_model(Tag, :name => "another_tag_for-link-1"),
mock_model(Tag, :name => "another_tag_for-link-2")],
:created_at => 1.hours.ago)
- assigns[:link] = @link
+ assign :link, @link
do_render
end
def do_render
- render :partial => "/tags/link.atom.erb", :object => @link, :locals => {:tag => @tag}
- @content = response.body
+ render :partial => 'tags/link.atom.erb', :locals => {:link => @link, :tag => @tag}
+ @content = rendered
end
it "sets the content properly" do
- @content.should have_tag('li') do
- with_tag('a', @link.title)
+ pending "have to deal with missing have_tag matcher in rspec-rails" do
+ @content.should have_tag('li') do
+ with_tag('a', @link.title)
- list_of_tags = (@link.tags - [@tag]).map(&:name).join(', ')
+ list_of_tags = (@link.tags - [@tag]).map(&:name).join(', ')
- with_tag('div.related', /Also seen in: #{Regexp.escape(list_of_tags)}/)
- end
+ with_tag('div.related', /Also seen in: #{Regexp.escape(list_of_tags)}/)
+ end
+ end
end
end
View
16 spec/views/tags/show.atom.erb_spec.rb
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe '/tags/show.atom.erb' do
+describe 'tags/show.atom.erb' do
+ helper(TagsHelper)
+
before(:each) do
@tag = mock_model(Tag, :name => 'a_tag')
@links = (1..20).map { |l| mock_model(Link,
@@ -12,15 +14,15 @@
name = "tag-#{t}-for-link-#{l}"
mock_model(Tag, :to_s => name,
:to_param => name, :name => name) } )}
- assigns[:tag] = @tag
- assigns[:links] = @links
+ assign :tag, @tag
+ assign :links, @links
do_render
end
def do_render
- render "/tags/show.atom.erb"
- @feed = Atom::Feed.load_feed(response.body)
+ render
+ @feed = Atom::Feed.load_feed(rendered)
end
it "has a proper title" do
@@ -68,7 +70,9 @@ def do_render
end
it "sets the content properly" do
- @entry.content.to_s.should have_tag("a[href=?]", @link.url, @link.title)
+ pending "have to deal with missing have_tag matcher in rspec-rails" do
+ @entry.content.to_s.should have_tag("a[href=?]", @link.url, @link.title)
+ end
end
end
end
View
20 spec/views/tags/summary.atom.erb_spec.rb
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe 'GET /tag/summary.atom.erb' do
+describe 'tags/summary.atom.erb' do
+ helper(TagsHelper)
+
before(:each) do
@tag_1 = stub_model(Tag, :name => 'tag_1')
@tag_2 = stub_model(Tag, :name => 'tag_2')
@@ -15,15 +17,15 @@
@tag_1.stub!(:todays_links).and_return(@links)
- assigns[:tag] = @tag_1
- assigns[:links] = @links
+ assign :tag, @tag_1
+ assign :links, @links
do_render
end
def do_render
- render "/tags/summary.atom.erb"
- @feed = Atom::Feed.load_feed(response.body)
+ render
+ @feed = Atom::Feed.load_feed(rendered)
end
it "has a proper title" do
@@ -72,10 +74,12 @@ def do_render
end
it "sets the content properly" do
- content = @entry.content.to_s
+ pending "have to deal with missing have_tag matcher in rspec-rails" do
+ content = @entry.content.to_s
- content.should have_tag("div.tag") do
- with_tag("h3", "Popular links seen on #{Date.today} for tag_1")
+ content.should have_tag("div.tag") do
+ with_tag("h3", "Popular links seen on #{Date.today} for tag_1")
+ end
end
end
end
View
28 spec/views/users/show.atom.erb_spec.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe '/users/show.atom.erb' do
+describe 'users/show.atom.erb' do
before(:each) do
@user = mock_model(User, :login => 'bob')
@links = (1..20).map { |l| mock_model(Link,
@@ -12,15 +12,15 @@
name = "tag-#{t}-for-link-#{l}"
mock_model(Tag, :to_s => name,
:to_param => name, :name => name) } )}
- assigns[:user] = @user
- assigns[:links] = @links
+ assign(:user, @user)
+ assign(:links, @links)
do_render
end
def do_render
- render "/users/show.atom.erb"
- @feed = Atom::Feed.load_feed(response.body)
+ render
+ @feed = Atom::Feed.load_feed(rendered)
end
it "has a proper title" do
@@ -68,15 +68,17 @@ def do_render
end
it "sets the content properly" do
- content = @entry.content.to_s
- content.should have_tag("div.title", @link.title)
- content.should have_tag("div.url") do
- with_tag("a[href=?]", @link.url)
- end
+ pending "have to deal with missing have_tag matcher in rspec-rails" do
+ content = @entry.content.to_s
+ content.should have_tag("div.title", @link.title)
+ content.should have_tag("div.url") do
+ with_tag("a[href=?]", @link.url)
+ end
- content.should have_tag("div.tags") do
- @link.tags.each do |tag|
- with_tag("a[href=?]", "http://test.host/tags/#{tag.name}")
+ content.should have_tag("div.tags") do
+ @link.tags.each do |tag|
+ with_tag("a[href=?]", "http://test.host/tags/#{tag.name}")
+ end
end
end
end
View
24 spec/views/users/summary.atom.erb_spec.rb
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "/users/summary.atom.erb" do
+describe "users/summary.atom.erb" do
+ helper(TagsHelper)
+
before(:each) do
@user = mock_model(User, :login => 'bob')
@@ -20,15 +22,15 @@
@latest_update = 2.minutes.ago
- assigns[:user] = @user
- assigns[:latest_update] = @latest_update
- assigns[:tags_with_links] = @tags_with_links
+ assign(:user, @user)
+ assign(:latest_update, @latest_update)
+ assign(:tags_with_links, @tags_with_links)
do_render
end
def do_render
- render "/users/summary.atom.erb", :helper => :tags
- @feed = Atom::Feed.load_feed(response.body)
+ render
+ @feed = Atom::Feed.load_feed(rendered)
end
it "has a proper title" do
@@ -75,10 +77,12 @@ def do_render
end
it "sets the content properly" do
- content = @entry.content.to_s
- @tags_with_links.each do |tag, links|
- content.should have_tag("div.tag") do
- with_tag('h3', "#{tag.name}")
+ pending "have to deal with missing have_tag matcher from rspec-rails" do
+ content = @entry.content.to_s
+ @tags_with_links.each do |tag, links|
+ content.should have_tag("div.tag") do
+ with_tag('h3', "#{tag.name}")
+ end
end
end
end

0 comments on commit f5e3a8d

Please sign in to comment.
Something went wrong with that request. Please try again.