Skip to content
Extraits de code Groupes Projets
Valider b105b0d6 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

merged in

parents 5cade230 720c68e2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -27,14 +27,15 @@ class Post ...@@ -27,14 +27,15 @@ class Post
def self.newest(person = nil) def self.newest(person = nil)
return self.last if person.nil? return self.last if person.nil?
self.where(:person_id => person.id).last
self.first(:person_id => person.id, :order => '_id desc')
end end
def self.my_newest def self.my_newest
self.newest(User.first) self.newest(User.first)
end end
def self.newest_by_email(email) def self.newest_by_email(email)
self.where(:person_id => Person.where(:email => email).first.id).last self.newest(Person.first(:email => email))
end end
......
...@@ -8,7 +8,7 @@ class User < Person ...@@ -8,7 +8,7 @@ class User < Person
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
before_save :do_bad_things before_validation :do_bad_things
def do_bad_things def do_bad_things
self.password_confirmation = self.password self.password_confirmation = self.password
......
require File.dirname(__FILE__) + '/../spec_helper'
describe BlogsController do
before do
#TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
u = Factory.build(:user, :email => "bob@aol.com", :password => "secret")
b = Factory.build(:blog, :title => "hello", :body => "sir")
u.save
b.save
end
render_views
it "index action should render index template" do
get :index
response.should render_template(:index)
end
it "show action should render show template" do
get :show, :id => Blog.first.id
response.should render_template(:show)
end
it "new action should render new template" do
get :new
response.should render_template(:new)
end
it "create action should render new template when model is invalid" do
Blog.any_instance.stubs(:valid?).returns(false)
post :create
response.should render_template(:new)
end
it "create action should redirect when model is valid" do
Blog.any_instance.stubs(:valid?).returns(true)
post :create
response.should redirect_to(blog_url(assigns[:blog]))
end
it "edit action should render edit template" do
get :edit, :id => Blog.first.id
response.should render_template(:edit)
end
it "update action should render edit template when model is invalid" do
Blog.any_instance.stubs(:valid?).returns(false)
put :update, :id => Blog.first.id
response.should render_template(:edit)
end
it "update action should redirect when model is valid" do
#TODO(dan) look into why we need to create a new bookmark object here
Blog.any_instance.stubs(:valid?).returns(true)
n = Blog.create
put :update, :id => n.id
response.should redirect_to(blog_url(assigns[:blog]))
end
it "destroy action should destroy model and redirect to index action" do
blog = Blog.first
delete :destroy, :id => blog.id
response.should redirect_to(blogs_url)
Blog.first(:conditions => {:id => blog.id }).nil?.should be true
end
end
require File.dirname(__FILE__) + '/../spec_helper'
describe BookmarksController do
before do
#TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
@bob = Factory.build(:user)
@bookmark = Factory.build(:bookmark)
@bob.save
@bookmark.save
end
render_views
it "index action should render index template" do
get :index
response.should render_template(:index)
end
it "edit action should render edit template" do
get :edit, :id => Bookmark.first.id
response.should render_template(:edit)
end
it "update action should render edit template when model is invalid" do
Bookmark.any_instance.stubs(:valid?).returns(false)
put :update, :id => Bookmark.first.id
response.should render_template(:edit)
end
it "update action should redirect when model is valid" do
#TODO(dan) look into why we need to create a new bookmark object here
Bookmark.any_instance.stubs(:valid?).returns(true)
n = Factory.create(:bookmark, :link => "http://hotub.com/")
n.save
put :update, :id => Bookmark.first.id
response.should redirect_to(bookmark_url(assigns[:bookmark]))
end
it "show action should render show template" do
get :show, :id => Bookmark.first.id
response.should render_template(:show)
end
it "create action should render new template when model is invalid" do
Bookmark.any_instance.stubs(:valid?).returns(false)
post :create
response.should render_template(:new)
end
it "create action should redirect when model is valid" do
Bookmark.any_instance.stubs(:valid?).returns(true)
post :create
response.should redirect_to(bookmark_url(assigns[:bookmark]))
end
it "new action should render new template" do
get :new
response.should render_template(:new)
end
it "destroy action should destroy model and redirect to index action" do
bookmark = Bookmark.first
delete :destroy, :id => bookmark.id
response.should redirect_to(bookmarks_url)
Bookmark.first(:conditions => {:id => bookmark.id }).nil?.should be true
end
end
require File.dirname(__FILE__) + '/../spec_helper'
describe FriendsController do
render_views
before do
#TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
Factory.create(:user)
@friend = Factory.build(:friend)
end
it "index action should render index template" do
get :index
response.should render_template(:index)
end
it "show action should render show template" do
@friend.save
get :show, :id => @friend.id
response.should render_template(:show)
end
it "destroy action should destroy model and redirect to index action" do
@friend.save
delete :destroy, :id => @friend.id
response.should redirect_to(friends_url)
Friend.first(:conditions => {:id => @friend.id}).should be_nil
end
it "new action should render new template" do
get :new
response.should render_template(:new)
end
it "create action should render new template when model is invalid" do
Friend.any_instance.stubs(:valid?).returns(false)
post :create
response.should render_template(:new)
end
it "create action should redirect when model is valid" do
Friend.any_instance.stubs(:valid?).returns(true)
post :create
response.should redirect_to(friend_url(assigns[:friend]))
end
it 'should test that a real creation adds to the database' do
end
it 'should have test that a delete removes a friend from the database' do
end
it 'should display a list of a friends posts on their page' do
friend = Factory.create(:friend)
@status_message = Factory.create(:status_message, :person => friend)
get :show, :id => friend.id
response.body.should include @status_message.message
end
end
require File.dirname(__FILE__) + '/../spec_helper'
describe StatusMessagesController do
before do
#TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
@bob = Factory.build(:user,:email => "bob@aol.com", :password => "secret")
@status_message = Factory.build(:status_message, :message => "yodels.")
@bob.save
@status_message.save #TODO for some reason it complains about validations even though they are valid fields
end
render_views
it "index action should render index template" do
get :index
response.should render_template(:index)
end
it "create action should render new template when model is invalid" do
StatusMessage.any_instance.stubs(:valid?).returns(false)
post :create
response.should render_template(:new)
end
it "create action should redirect when model is valid" do
StatusMessage.any_instance.stubs(:valid?).returns(true)
post :create
response.should redirect_to(status_messages_url)
end
it "new action should render new template" do
get :new
response.should render_template(:new)
end
it "destroy action should destroy model and redirect to index action" do
delete :destroy, :id => @status_message._id
response.should redirect_to(status_messages_url)
StatusMessage.first(:conditions => {:id => @status_message.id }).nil?.should be true
end
it "show action should render show template" do
get :show, :id => @status_message.post_id
response.should render_template(:show)
end
it "should return xml on show type if the MIME type exists" do
request.env["HTTP_ACCEPT"] = "application/xml"
message = StatusMessage.first
get :show, :id => message.post_id
response.body.include?(message.to_xml.to_s).should be true
end
it "should return xml on index if the MIME type exists" do
Factory.create(:status_message)
request.env["HTTP_ACCEPT"] = "application/xml"
get :index
StatusMessage.all.each do |message|
response.body.include?(message.message).should be true
response.body.include?(message.person.email).should be true
end
end
end
require File.dirname(__FILE__) + '/../spec_helper'
describe UsersController do
before do
render_views
end
end
...@@ -7,7 +7,7 @@ describe Diaspora do ...@@ -7,7 +7,7 @@ describe Diaspora do
describe Webhooks do describe Webhooks do
before do before do
Factory.create(:user, :email => "bob@aol.com") @user = Factory.create(:user, :email => "bob@aol.com")
end end
describe "header" do describe "header" do
...@@ -35,7 +35,7 @@ describe Diaspora do ...@@ -35,7 +35,7 @@ describe Diaspora do
describe "body" do describe "body" do
before do before do
@post = Factory.create(:status_message) @post = Factory.create(:status_message, :person => @user)
end end
it "should add the following methods to Post on inclusion" do it "should add the following methods to Post on inclusion" do
......
...@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper' ...@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Blog do describe Blog do
before do before do
Factory.create(:user, :email => "bob@aol.com") @user = Factory.create(:user, :email => "bob@aol.com")
end end
it "should have a title and body" do it "should have a title and body" do
...@@ -14,37 +14,8 @@ describe Blog do ...@@ -14,37 +14,8 @@ describe Blog do
n.valid?.should be true n.valid?.should be true
end end
it "should add an owner if none is present" do
b = Factory.create(:blog)
b.person.email.should == "bob@aol.com"
end
describe "newest" do
before do
@friend_one = Factory.create(:friend, :email => "some@dudes.com")
@friend_two = Factory.create(:friend, :email => "other@dudes.com")
(2..4).each { Factory.create(:blog, :person => @friend_one) }
(5..8).each { Factory.create(:blog) }
(9..11).each { Factory.create(:blog, :person => @friend_two) }
Factory.create(:status_message)
Factory.create(:bookmark)
end
it "should give the most recent blog title and body from owner" do
blog = Blog.newest(User.first)
blog.class.should == Blog
blog.title.should == "bobby's 8 penguins"
blog.body.should == "jimmy's huge 8 whales"
end
it "should give the most recent blog body for a given email" do
blog = Blog.newest_by_email("some@dudes.com")
blog.class.should == Blog
blog.title.should == "bobby's 14 penguins"
blog.body.should == "jimmy's huge 14 whales"
end
end
describe "XML" do describe "XML" do
it 'should serialize to XML' do it 'should serialize to XML' do
body = Factory.create(:blog, :title => "yessir", :body => "penguins") body = Factory.create(:blog, :title => "yessir", :body => "penguins")
......
...@@ -8,12 +8,6 @@ describe Bookmark do ...@@ -8,12 +8,6 @@ describe Bookmark do
bookmark.valid?.should be true bookmark.valid?.should be true
end end
it "should add an owner if none is present" do
Factory.create(:user, :email => "bob@aol.com")
n = Factory.create(:bookmark)
n.person.email.should == "bob@aol.com"
end
it 'should validate its link' do it 'should validate its link' do
bookmark = Factory.build(:bookmark) bookmark = Factory.build(:bookmark)
......
...@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper' ...@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Post do describe Post do
before do before do
Factory.create(:user, :email => "bob@aol.com") @user = Factory.create(:user, :email => "bob@aol.com")
end end
describe 'defaults' do describe 'defaults' do
...@@ -17,7 +17,35 @@ describe Post do ...@@ -17,7 +17,35 @@ describe Post do
end end
describe "newest" do
before do
@friend_one = Factory.create(:friend, :email => "some@dudes.com")
@friend_two = Factory.create(:friend, :email => "other@dudes.com")
(2..4).each {|n| Blog.create(:title => "title #{n}", :body => "test #{n}", :person => @friend_one)}
(5..8).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @user)}
(9..11).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @friend_two)}
Factory.create(:status_message)
Factory.create(:bookmark)
end
it "should give the most recent blog title and body from owner" do
blog = Blog.my_newest()
blog.person.email.should == @user.email
blog.class.should == Blog
blog.title.should == "title 8"
blog.body.should == "test 8"
end
it "should give the most recent blog body for a given email" do
blog = Blog.newest_by_email("some@dudes.com")
blog.person.email.should == @friend_one.email
blog.class.should == Blog
blog.title.should == "title 4"
blog.body.should == "test 4"
end
end
describe "stream" do describe "stream" do
before do before do
@owner = Factory.create(:user, :email => "robert@grimm.com") @owner = Factory.create(:user, :email => "robert@grimm.com")
......
...@@ -12,30 +12,6 @@ describe StatusMessage do ...@@ -12,30 +12,6 @@ describe StatusMessage do
n.valid?.should be true n.valid?.should be true
end end
it "should add an owner if none is present" do
n = Factory.create(:status_message)
n.person.email.should == "bob@aol.com"
end
describe "newest" do
before do
@person_one = Factory.create(:friend,:email => "some@dudes.com")
(1..10).each { Factory.create(:status_message, :person => @person_one) }
(1..5).each { Factory.create(:status_message) }
Factory.create(:bookmark)
Factory.create(:bookmark, :person => @person_one)
end
it "should give the most recent message from a friend" do
StatusMessage.newest(@person_one).message.should == "jimmy's 13 whales"
end
it "should give the most recent message for a given email" do
StatusMessage.newest_by_email(@person_one.email).message.should == "jimmy's 28 whales"
end
end
describe "XML" do describe "XML" do
it 'should serialize to XML' do it 'should serialize to XML' do
message = Factory.create(:status_message, :message => "I hate WALRUSES!") message = Factory.create(:status_message, :message => "I hate WALRUSES!")
......
...@@ -11,7 +11,7 @@ include Devise::TestHelpers ...@@ -11,7 +11,7 @@ include Devise::TestHelpers
# in ./support/ and its subdirectories. # in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
Rspec.configure do |config| RSpec.configure do |config|
config.mock_with :rspec config.mock_with :rspec
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter