moved render_views out of controller specs to spec_helper.

cleaned up indentation and spacing in controller specs.
This commit is contained in:
Arzumy MD 2011-05-07 18:38:40 +08:00
parent 160e01f7bd
commit 3767cce149
29 changed files with 207 additions and 127 deletions

View file

@ -1,29 +1,34 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe AdminsController do
render_views
before do
@user = Factory :user
sign_in :user, @user
end
it 'is behind redirect_unless_admin' do
get :user_search
response.should redirect_to root_url
describe '#user_search' do
context 'admin not signed in' do
it 'is behind redirect_unless_admin' do
get :user_search
response.should redirect_to root_url
end
end
context 'admin signed in' do
before do
AppConfig[:admins] = [@user.username]
end
context 'admin signed in' do
before do
AppConfig[:admins] = [@user.username]
end
describe '#user_search' do
it 'succeeds' do
get :user_search
response.should be_success
end
it 'assings users to an empty array if nothing is searched for' do
it 'assigns users to an empty array if nothing is searched for' do
get :user_search
assigns[:users].should == []
end
@ -52,13 +57,20 @@ describe AdminsController do
assigns[:users].should == [@user]
end
end
end
describe '#admin_inviter' do
context 'admin signed in' do
before do
AppConfig[:admins] = [@user.username]
end
describe '#admin_inviter' do
it 'invites a new user' do
Invitation.should_receive(:create_invitee).with(:service => 'email', :identifier => 'bob@moms.com')
get :admin_inviter, :identifier => 'bob@moms.com'
response.should be_redirect
end
it 'passes an existing user to create_invitee' do
Factory.create(:user, :email => 'bob@moms.com')
bob = User.where(:email => 'bob@moms.com').first

View file

@ -1,7 +1,11 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe ApisController do
before(:all) do
before do
@status_message1 = Factory(:status_message, :text => '#bobby #flay #sux', :public => true, :updated_at => Time.now + 20)
@status_message2 = Factory(:status_message, :text => '#aobby', :public => true, :created_at => Time.now + 10)

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe ApplicationController do
@ -5,19 +9,23 @@ describe ApplicationController do
def user_signed_in?
nil
end
def current_user
nil
end
def index
render :nothing => true
end
end
describe '#set_git_headers' do
context 'with git info' do
before do
AppConfig[:git_update] = 'yesterday'
AppConfig[:git_revision] = '02395'
end
it 'sets the git header if there is git info' do
get :index
response.headers['X-Git-Update'].should == 'yesterday'

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe AspectMembershipsController do
render_views
before do
@user = alice
@user2 = bob

View file

@ -6,8 +6,6 @@ require 'spec_helper'
require File.join(Rails.root, "spec", "shared_behaviors", "log_override")
describe AspectsController do
render_views
before do
@bob = bob
@alice = alice
@ -241,27 +239,31 @@ describe AspectsController do
get :manage
response.should be_success
end
it "performs reasonably", :performance => true do
require 'benchmark'
8.times do |n|
aspect = @alice.aspects.create(:name => "aspect#{n}")
8.times do |o|
person = Factory(:person)
@alice.activate_contact(person, aspect)
end
require 'benchmark'
8.times do |n|
aspect = @alice.aspects.create(:name => "aspect#{n}")
8.times do |o|
person = Factory(:person)
@alice.activate_contact(person, aspect)
end
Benchmark.realtime{
get :manage
}.should < 4.5
end
Benchmark.realtime{
get :manage
}.should < 4.5
end
it "assigns aspect to manage" do
get :manage
assigns(:aspect).should == :manage
end
it "assigns remote_requests" do
get :manage
assigns(:remote_requests).should be_empty
end
it "assigns contacts to only non-pending" do
contact = @alice.contact_for(bob.person)
Contact.unscoped.where(:user_id => @alice.id).count.should == 1
@ -273,6 +275,7 @@ describe AspectsController do
contacts.count.should == 1
contacts.first.should == contact
end
context "when the user has pending requests" do
before do
requestor = Factory.create(:user)
@ -283,18 +286,22 @@ describe AspectsController do
requestor_aspect.reload
@alice.reload
end
it "succeeds" do
get :manage
response.should be_success
end
it "assigns aspect to manage" do
get :manage
assigns(:aspect).should == :manage
end
it "assigns remote_requests" do
get :manage
assigns(:remote_requests).count.should == 1
end
it "generates a jasmine fixture" do
get :manage
save_fixture(html_for("body"), "aspects_manage")
@ -306,6 +313,7 @@ describe AspectsController do
before do
@alices_aspect_1 = @alice.aspects.create(:name => "Bruisers")
end
it "doesn't overwrite random attributes" do
new_user = Factory.create :user
params = {"name" => "Bruisers"}
@ -336,6 +344,7 @@ describe AspectsController do
connect_users(@alice, @alices_aspect_2, @zed, @zed.aspects.first)
connect_users(@alice, @alices_aspect_1, @katz, @katz.aspects.first)
end
it 'renders' do
get :edit, :id => @alices_aspect_1.id
response.should be_success
@ -371,4 +380,4 @@ describe AspectsController do
@alices_aspect_1.reload.contacts_visible.should be_false
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe CommentsController do
render_views
before do
@aspect1 = alice.aspects.first
@aspect2 = bob.aspects.first
@ -20,10 +18,12 @@ describe CommentsController do
{:text =>"facebook, is that you?",
:post_id =>"#{@post.id}"}
}
context "on my own post" do
before do
@post = alice.post :status_message, :text => 'GIANTS', :to => @aspect1.id
end
it 'responds to format js' do
post :create, comment_hash.merge(:format => 'js')
response.code.should == '201'
@ -35,16 +35,19 @@ describe CommentsController do
before do
@post = bob.post :status_message, :text => 'GIANTS', :to => @aspect2.id
end
it 'comments' do
post :create, comment_hash
response.code.should == '201'
end
it "doesn't overwrite author_id" do
new_user = Factory.create(:user)
comment_hash[:author_id] = new_user.person.id.to_s
post :create, comment_hash
Comment.find_by_text(comment_hash[:text]).author_id.should == alice.person.id
end
it "doesn't overwrite id" do
old_comment = alice.comment("hello", :on => @post)
comment_hash[:id] = old_comment.id
@ -52,10 +55,12 @@ describe CommentsController do
old_comment.reload.text.should == 'hello'
end
end
context 'on a post from a stranger' do
before do
@post = eve.post :status_message, :text => 'GIANTS', :to => eve.aspects.first.id
end
it 'posts no comment' do
alice.should_not_receive(:comment)
post :create, comment_hash
@ -72,6 +77,7 @@ describe CommentsController do
@comment2 = bob.comment("hey", :on => @message)
@comment3 = eve.comment("hey", :on => @message)
end
it 'lets the user delete his comment' do
alice.should_receive(:retract).with(@comment)
delete :destroy, :format => "js", :id => @comment.id
@ -106,4 +112,4 @@ describe CommentsController do
end
end
end
end
end

View file

@ -2,12 +2,9 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe ContactsController do
render_views
before do
@user = alice
@user2 = bob
@ -37,12 +34,12 @@ describe ContactsController do
end
describe '#create' do
context 'with an incoming request' do
before do
@user3 = Factory.create(:user)
@user3.send_contact_request_to(@user.person, @user3.aspects.create(:name => "Walruses"))
end
it 'deletes the request' do
post :create,
:format => 'js',
@ -50,6 +47,7 @@ describe ContactsController do
:aspect_id => @aspect1.id
Request.where(:sender_id => @user3.person.id, :recipient_id => @user.person.id).first.should be_nil
end
it 'does not leave the contact pending' do
post :create,
:format => 'js',
@ -58,6 +56,7 @@ describe ContactsController do
@user.contact_for(@user3.person).should_not be_pending
end
end
context 'with a non-contact' do
before do
@person = Factory(:person)
@ -125,4 +124,4 @@ describe ContactsController do
response.should redirect_to(@contact.person)
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe ConversationVisibilitiesController do
render_views
before do
@user1 = alice
sign_in :user, @user1
@ -32,4 +30,4 @@ describe ConversationVisibilitiesController do
}.should_not change(ConversationVisibility, :count)
end
end
end
end

View file

@ -1,8 +1,10 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe ConversationsController do
render_views
before do
sign_in :user, alice
end
@ -11,12 +13,15 @@ describe ConversationsController do
before do
get :new
end
it 'succeeds' do
response.should be_success
end
it "assigns a json list of contacts" do
assigns(:contacts_json).should include(alice.contacts.first.person.name)
end
it "assigns a contact if passed a contact id" do
get :new, :contact_id => alice.contacts.first.id
assigns(:contact).should == alice.contacts.first

View file

@ -6,8 +6,6 @@ require 'spec_helper'
require File.join(Rails.root, "spec", "shared_behaviors", "log_override")
describe HomeController do
render_views
before do
@user = alice
sign_in @user
@ -36,22 +34,24 @@ describe HomeController do
get :show
response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] )
end
end
describe "custom logging on success" do
before do
@action = :show
@action_params = {"lasers" => "green"}
end
it_should_behave_like "it overrides the logs on success"
end
describe "custom logging on success" do
before do
@action = :show
@action_params = {"lasers" => "green"}
end
describe "custom logging on redirect" do
before do
sign_in :user, bob
@action = :show
@action_params = {"lasers" => "green"}
it_should_behave_like "it overrides the logs on success"
end
describe "custom logging on redirect" do
before do
sign_in :user, bob
@action = :show
@action_params = {"lasers" => "green"}
end
it_should_behave_like "it overrides the logs on redirect"
end
it_should_behave_like "it overrides the logs on redirect"
end
end
end

View file

@ -7,8 +7,6 @@ require 'spec_helper'
describe InvitationsController do
include Devise::TestHelpers
render_views
before do
@user = alice
@aspect = @user.aspects.first
@ -77,8 +75,10 @@ describe InvitationsController do
:invitation_token => @invited_user.invitation_token}}
end
context 'success' do
let(:invited) {User.find_by_username(@accept_params[:user][:username])}
it 'creates a user' do
put :update, @accept_params
invited.should_not be_nil
@ -95,15 +95,18 @@ describe InvitationsController do
end
end
context 'failure' do
before do
@fail_params = @accept_params
@fail_params[:user][:username] = @user.username
end
it 'stays on the invitation accept form' do
put :update, @fail_params
response.location.include?(accept_user_invitation_path).should be_true
end
it 'keeps the invitation token' do
put :update, @fail_params
response.location.include?("invitation_token=#{@invited_user.invitation_token}").should be_true
@ -145,5 +148,4 @@ describe InvitationsController do
put :resend, :id => invitation2.id
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe LikesController do
render_views
before do
@user1 = alice
@user2 = bob
@ -26,10 +24,12 @@ describe LikesController do
{:positive => 0,
:post_id => "#{@post.id}"}
}
context "on my own post" do
before do
@post = @user1.post :status_message, :text => "AWESOME", :to => @aspect1.id
end
it 'responds to format js' do
post :create, like_hash.merge(:format => 'js')
response.code.should == '201'
@ -40,24 +40,29 @@ describe LikesController do
before do
@post = @user2.post :status_message, :text => "AWESOME", :to => @aspect2.id
end
it 'likes' do
post :create, like_hash
response.code.should == '201'
end
it 'dislikes' do
post :create, dislike_hash
response.code.should == '201'
end
it "doesn't post multiple times" do
@user1.like(1, :on => @post)
post :create, dislike_hash
response.code.should == '422'
end
end
context "on a post from a stranger" do
before do
@post = eve.post :status_message, :text => "AWESOME", :to => eve.aspects.first.id
end
it "doesn't post" do
@user1.should_not_receive(:like)
post :create, like_hash
@ -65,4 +70,4 @@ describe LikesController do
end
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe MessagesController do
render_views
before do
@user1 = alice
@user2 = bob
@ -22,11 +20,13 @@ describe MessagesController do
@create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id],
:subject => "cool stuff", :text => "stuff"}
end
context "on my own post" do
before do
@cnv = Conversation.create(@create_hash)
@message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}}
end
it 'redirects to conversation' do
lambda{
post :create, @message_hash
@ -42,17 +42,20 @@ describe MessagesController do
@cnv = Conversation.create(@create_hash)
@message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}}
end
it 'comments' do
post :create, @message_hash
response.code.should == '302'
response.should redirect_to(conversations_path(:conversation_id => @cnv))
end
it "doesn't overwrite author_id" do
new_user = Factory.create(:user)
@message_hash[:author_id] = new_user.person.id.to_s
post :create, @message_hash
Message.find_by_text(@message_hash[:message][:text]).author_id.should == @user1.person.id
end
it "doesn't overwrite id" do
old_message = Message.create(:text => "hello", :author_id => @user1.person.id, :conversation_id => @cnv.id)
@message_hash[:id] = old_message.id
@ -60,6 +63,7 @@ describe MessagesController do
old_message.reload.text.should == 'hello'
end
end
context 'on a post from a stranger' do
before do
@create_hash[:author] = eve.person
@ -67,10 +71,11 @@ describe MessagesController do
@cnv = Conversation.create(@create_hash)
@message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}}
end
it 'posts no comment' do
post :create, @message_hash
response.code.should == '422'
end
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe NotificationsController do
before do
@user = alice
@aspect = @user.aspects.first
@ -57,4 +55,4 @@ describe NotificationsController do
assigns[:notifications].count.should == 1
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe PeopleController do
render_views
before do
@user = alice
@aspect = @user.aspects.first
@ -25,14 +23,17 @@ describe PeopleController do
get :index, :q => "Korth", :format => 'json'
response.body.should == [@korth].to_json
end
it 'does not set @hashes in a json request' do
get :index, :q => "Korth", :format => 'json'
assigns[:hashes].should be_nil
end
it 'sets @hashes in an html request' do
get :index, :q => "Korth"
assigns[:hashes].should_not be_nil
end
it "assigns people" do
eugene2 = Factory.create(:person,
:profile => Factory.build(:profile, :first_name => "Eugene",
@ -144,6 +145,7 @@ describe PeopleController do
sign_out :user
@person = bob.person
end
it "succeeds" do
get :show, :id => @person.id
response.status.should == 200
@ -183,6 +185,7 @@ describe PeopleController do
response.status.should == 404
end
end
context "when the person is a contact of the current user" do
before do
@person = bob.person
@ -249,6 +252,7 @@ describe PeopleController do
end
end
end
describe '#contacts' do
it 'assigns the contacts of a person' do
contact = alice.contact_for(bob.person)
@ -264,4 +268,4 @@ describe PeopleController do
get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe PhotosController do
render_views
before do
@alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id)
@bobs_photo = bob.post(:photo, :user_file => uploaded_photo, :to => bob.aspects.first.id, :public => true)
@ -55,51 +53,62 @@ describe PhotosController do
before do
get :show, :id => @alices_photo.id
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @alices_photo
assigns[:ownership].should be_true
end
end
context "private photo user can see" do
before do
get :show, :id => @bobs_photo.id
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @bobs_photo
assigns[:ownership].should be_false
end
end
context "private photo user cannot see" do
before do
user3 = Factory(:user_with_aspect)
@photo = user3.post(:photo, :user_file => uploaded_photo, :to => user3.aspects.first.id)
end
it "redirects to the referrer" do
request.env["HTTP_REFERER"] = "http://google.com"
get :show, :id => @photo.to_param
response.should redirect_to("http://google.com")
end
it "redirects to the aspects page if there's no referrer" do
request.env.delete("HTTP_REFERER")
get :show, :id => @photo.to_param
response.should redirect_to(aspects_path)
end
end
context "public photo" do
before do
user3 = Factory(:user_with_aspect)
@photo = user3.post(:photo, :user_file => uploaded_photo, :to => user3.aspects.first.id, :public => true)
get :show, :id => @photo.to_param
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @photo
assigns[:ownership].should be_false
@ -164,7 +173,6 @@ describe PhotosController do
end
describe "#make_profile_photo" do
it 'should return a 201 on a js success' do
get :make_profile_photo, :photo_id => @alices_photo.id, :format => 'js'
response.code.should == "201"
@ -174,7 +182,5 @@ describe PhotosController do
get :make_profile_photo, :photo_id => @bobs_photo.id
response.code.should == "422"
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe PostVisibilitiesController do
render_views
before do
@user1 = alice
@bob = bob
@ -16,7 +14,6 @@ describe PostVisibilitiesController do
a2.contacts << bob.contact_for(alice.person)
a2.save
@status = bob.post(:status_message, :text => "hello", :public => true, :to => a2)
@vis = @status.post_visibilities.first
@vis.reload.hidden.should == false
@ -47,15 +44,17 @@ describe PostVisibilitiesController do
user2 = eve
sign_in :user, user2
end
it 'does not let a user destroy a visibility that is not theirs' do
lambda {
put :update, :format => :js, :id => 42, :post_id => @status.id
}.should_not change(@vis.reload, :hidden).to(true)
end
it 'does not succceed' do
it 'does not succeed' do
put :update, :format => :js, :id => 42, :post_id => @status.id
response.should_not be_success
end
end
end
end
end

View file

@ -5,11 +5,10 @@
require 'spec_helper'
describe PostsController do
render_views
before do
@user = alice
end
describe '#show' do
it 'shows a public post' do
status = @user.post(:status_message, :text => "hello", :public => true, :to => 'all')

View file

@ -2,11 +2,9 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe ProfilesController do
render_views
before do
@user = eve
sign_in :user, @user
@ -63,6 +61,7 @@ describe ProfilesController do
@user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg"
@user.person.profile.save
end
it "doesn't overwrite the profile photo when an empty string is passed in" do
image_url = @user.person.profile.image_url
put :update, @params
@ -77,6 +76,7 @@ describe ProfilesController do
@profile_params = {:profile =>{ :person_id => new_person.id,
:diaspora_handle => 'abc@a.com'}}
end
it 'person_id' do
person = @user.person
profile = person.profile
@ -90,4 +90,4 @@ describe ProfilesController do
end
end
end
end
end

View file

@ -5,7 +5,6 @@
require 'spec_helper'
describe PublicsController do
render_views
let(:fixture_path) { File.join(Rails.root, 'spec', 'fixtures')}
before do
@user = alice
@ -20,6 +19,7 @@ describe PublicsController do
save_fixture(response.body, "host-meta", fixture_path)
end
end
describe '#receive' do
let(:xml) { "<walruses></walruses>" }
@ -111,4 +111,4 @@ describe PublicsController do
response.should be_success
end
end
end
end

View file

@ -7,8 +7,6 @@ require 'spec_helper'
describe RegistrationsController do
include Devise::TestHelpers
render_views
before do
request.env["devise.mapping"] = Devise.mappings[:user]
@valid_params = {:user => {
@ -24,14 +22,17 @@ describe RegistrationsController do
before do
AppConfig[:registrations_closed] = true
end
after do
AppConfig[:registrations_closed] = false
end
it 'redirects #new to the login page' do
get :new
flash[:error].should == I18n.t('registrations.closed')
response.should redirect_to new_user_session_path
end
it 'redirects #create to the login page' do
post :create, @valid_params
flash[:error].should == I18n.t('registrations.closed')
@ -45,47 +46,57 @@ describe RegistrationsController do
user = Factory.build(:user)
User.stub!(:build).and_return(user)
end
it "creates a user" do
lambda {
get :create, @valid_params
}.should change(User, :count).by(1)
end
it "assigns @user" do
get :create, @valid_params
assigns(:user).should be_true
end
it "sets the flash" do
get :create, @valid_params
flash[:notice].should_not be_empty
end
it "redirects to the root path" do
get :create, @valid_params
response.should redirect_to root_path
end
end
context "with invalid parameters" do
before do
@invalid_params = @valid_params
@invalid_params[:user][:password_confirmation] = "baddword"
end
it "does not create a user" do
lambda { get :create, @invalid_params }.should_not change(User, :count)
end
it "does not create a person" do
lambda { get :create, @invalid_params }.should_not change(Person, :count)
end
it "assigns @user" do
get :create, @invalid_params
assigns(:user).should_not be_nil
end
it "sets the flash error" do
get :create, @invalid_params
flash[:error].should_not be_blank
end
it "re-renders the form" do
get :create, @invalid_params
response.should render_template("registrations/new")
end
end
end
end
end

View file

@ -5,7 +5,6 @@
require 'spec_helper'
describe RequestsController do
render_views
before do
@user = alice
@other_user = eve
@ -20,6 +19,7 @@ describe RequestsController do
@other_user.send_contact_request_to(@user.person, @other_user.aspects.first)
@friend_request = Request.where(:recipient_id => @user.person.id).first
end
describe 'when accepting a contact request' do
it "succeeds" do
xhr :delete, :destroy,
@ -28,6 +28,7 @@ describe RequestsController do
:id => @friend_request.id.to_s
response.should redirect_to(requests_path)
end
it "marks the notification as read" do
notification = Notification.where(:recipient_id => @user.id, :target_id=> @friend_request.id).first
notification.unread = true
@ -39,12 +40,14 @@ describe RequestsController do
notification.reload.unread.should == false
end
end
describe 'when ignoring a contact request' do
it "succeeds" do
xhr :delete, :destroy,
:id => @friend_request.id.to_s
response.should be_success
end
it "removes the request object" do
lambda {
xhr :delete, :destroy,
@ -71,6 +74,7 @@ describe RequestsController do
:into => @user.aspects[0].id
}}
end
it 'creates a contact' do
@user.contact_for(@other_user).should be_nil
lambda {
@ -80,12 +84,14 @@ describe RequestsController do
new_contact.should_not be_nil
new_contact.should be_pending
end
it 'does not persist a Request' do
lambda {
post :create, @params
}.should_not change(Request, :count)
end
end
it 'autoaccepts and when sending a request to someone who sent me a request' do
@other_user.send_contact_request_to(@user.person, @other_user.aspects[0])
@ -138,4 +144,4 @@ describe RequestsController do
response.should redirect_to :back
end
end
end
end

View file

@ -5,7 +5,6 @@
require 'spec_helper'
describe ServicesController do
render_views
let(:mock_access_token) { Object.new }
let(:omniauth_auth) {
@ -60,7 +59,6 @@ describe ServicesController do
response.should redirect_to services_url
end
it 'creates a twitter service' do
Service.delete_all
@user.getting_started = false
@ -74,6 +72,7 @@ describe ServicesController do
before do
@service1 = Factory.create(:service, :user => @user)
end
it 'destroys a service selected by id' do
lambda{
delete :destroy, :id => @service1.id
@ -97,6 +96,7 @@ describe ServicesController do
get :finder, :provider => @service1.provider
response.should be_success
end
it 'has no translations missing' do
get :finder, :provider => @service1.provider
response.body.match(/translation/).should be_nil
@ -104,7 +104,6 @@ describe ServicesController do
end
describe '#invite' do
before do
@uid = "abc"
@invite_params = {:provider => 'facebook', :uid => @uid, :aspect_id => @user.aspects.first.id}
@ -140,5 +139,4 @@ describe ServicesController do
}.should_not change(Invitation, :count)
end
end
end
end

View file

@ -12,8 +12,6 @@ end
describe SessionsController do
include Devise::TestHelpers
render_views
let(:mock_access_token) { Object.new }
@ -34,4 +32,4 @@ describe SessionsController do
"password"=>"evankorth"}}
end
end
end
end

View file

@ -11,7 +11,6 @@ SocketsController.class_eval <<-EOT
EOT
describe SocketsController do
render_views
before do
@user = alice
@controller = SocketsController.new
@ -33,6 +32,7 @@ describe SocketsController do
json.include?("html\":null").should be_true
end
end
describe '#outgoing' do
it 'calls queue_to_user' do
Diaspora::WebSocket.should_receive(:is_connected?).with(@user.id).and_return(true)
@ -45,10 +45,11 @@ describe SocketsController do
Diaspora::WebSocket.should_not_receive(:queue_to_user)
@controller.outgoing(@user.id, @message)
end
it 'takes a user or an id' do
Diaspora::WebSocket.should_receive(:is_connected?).with(@user.id).and_return(false)
Diaspora::WebSocket.should_not_receive(:queue_to_user)
@controller.outgoing(@user, @message)
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe StatusMessagesController do
render_views
before do
@aspect1 = alice.aspects.first
@aspect2 = bob.aspects.first
@ -31,14 +29,14 @@ describe StatusMessagesController do
response.should be_success
end
it 'generates a jasmine fixture' do
contact = alice.contact_for(bob.person)
aspect = alice.aspects.create(:name => 'people')
contact.aspects << aspect
contact.save
get :new, :person_id => bob.person.id, :layout => true
save_fixture(html_for("body"), "status_message_new")
end
it 'generates a jasmine fixture' do
contact = alice.contact_for(bob.person)
aspect = alice.aspects.create(:name => 'people')
contact.aspects << aspect
contact.save
get :new, :person_id => bob.person.id, :layout => true
save_fixture(html_for("body"), "status_message_new")
end
end
describe '#show' do
@ -65,7 +63,6 @@ describe StatusMessagesController do
}.should change(note, :unread).from(true).to(false)
end
it 'redirects to back if there is no status message' do
get :show, :id => 2345
response.status.should == 302
@ -80,17 +77,20 @@ describe StatusMessagesController do
},
:aspect_ids => [@aspect1.id.to_s] }
}
context 'js requests' do
it 'responds' do
post :create, status_message_hash.merge(:format => 'js')
response.status.should == 201
end
it 'responds with json' do
post :create, status_message_hash.merge(:format => 'js')
json = JSON.parse(response.body)
json['post_id'].should_not be_nil
json['html'].should_not be_nil
end
it 'escapes XSS' do
xss = "<script> alert('hi browser') </script>"
post :create, status_message_hash.merge(:format => 'js', :text => xss)
@ -128,12 +128,12 @@ describe StatusMessagesController do
}
post :create, status_message_hash
end
it 'sends the errors in the body on js' do
post :create, status_message_hash.merge!(:format => 'js', :status_message => {:text => ''})
response.body.should include('Status message requires a message or at least one photo')
end
context 'with photos' do
before do
fixture_filename = 'button.png'

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe TagsController do
render_views
describe '#index (search)' do
before do
sign_in :user, alice
@ -26,10 +24,12 @@ describe TagsController do
get :index, :q => "c", :format => 'json'
response.body.should_not include("#cats")
end
it 'redirects the aimless to excellent parties' do
get :index
response.should redirect_to tag_path('partytimeexcellent')
end
it 'does not allow json requestors to party' do
get :index, :format => :json
response.status.should == 422
@ -37,24 +37,25 @@ describe TagsController do
end
describe '#show' do
context 'signed in' do
before do
sign_in :user, alice
end
it 'displays your own post' do
my_post = alice.post(:status_message, :text => "#what", :to => 'all')
get :show, :name => 'what'
assigns(:posts).models.should == [my_post]
response.status.should == 200
end
it "displays a friend's post" do
other_post = bob.post(:status_message, :text => "#hello", :to => 'all')
get :show, :name => 'hello'
assigns(:posts).models.should == [other_post]
response.status.should == 200
end
it 'displays a public post' do
other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all')
get :show, :name => 'hello'
@ -71,26 +72,32 @@ describe TagsController do
alice.profile.save!
get :show, :name => "whatevs"
end
it "succeeds" do
response.should be_success
end
it "assigns the right set of people" do
assigns(:people).should == [alice.person]
end
end
context "when there are posts to display" do
before do
@post = alice.post(:status_message, :text => "#what", :public => true, :to => 'all')
alice.post(:status_message, :text => "#hello", :public => true, :to => 'all')
end
it "succeeds" do
get :show, :name => 'what'
response.should be_success
end
it "assigns the right set of posts" do
get :show, :name => 'what'
assigns[:posts].models.should == [@post]
end
it 'succeeds with comments' do
alice.comment('what WHAT!', :on => @post)
get :show, :name => 'what'
@ -99,4 +106,4 @@ describe TagsController do
end
end
end
end
end

View file

@ -5,8 +5,6 @@
require 'spec_helper'
describe UsersController do
render_views
before do
@user = alice
@aspect = @user.aspects.first
@ -48,6 +46,7 @@ describe UsersController do
:user => { :diaspora_handle => "notreal@stuff.com" } }
end
it "doesn't overwrite random attributes" do
lambda {
put :update, @params
@ -123,7 +122,6 @@ describe UsersController do
proc{
put :update, par
}.should change(@user.user_preferences, :count).by(-1)
end
end
end
@ -140,4 +138,4 @@ describe UsersController do
assigns[:email_prefs]['mentioned'].should be_false
end
end
end
end

View file

@ -40,6 +40,10 @@ RSpec.configure do |config|
$process_queue = false
end
config.before(:each, :type => :controller) do
self.class.render_views
end
end
disable_typhoeus