Merge branch 'whitespace-cleanese' of git://github.com/goshakkk/discourse

Conflicts:
	lib/oneboxer.rb
	lib/oneboxer/whitelist.rb
	spec/controllers/robots_txt_controller_spec.rb
This commit is contained in:
Robin Ward
2013-02-26 10:42:49 -05:00
383 changed files with 4225 additions and 2226 deletions

View File

@ -9,7 +9,7 @@ describe Admin::EmailLogsController do
let!(:user) { log_in(:admin) }
context '.index' do
before do
before do
xhr :get, :index
end
@ -26,7 +26,7 @@ describe Admin::EmailLogsController do
context 'with an email address' do
it 'enqueues a test email job' do
Jobs.expects(:enqueue).with(:test_email, to_address: 'eviltrout@test.domain')
Jobs.expects(:enqueue).with(:test_email, to_address: 'eviltrout@test.domain')
xhr :post, :test, email_address: 'eviltrout@test.domain'
end
@ -34,4 +34,4 @@ describe Admin::EmailLogsController do
end
end
end

View File

@ -4,7 +4,7 @@ describe Admin::ExportController do
it "is a subclass of AdminController" do
(Admin::ExportController < Admin::AdminController).should be_true
end
context 'while logged in as an admin' do
before do
@user = log_in(:admin)
@ -54,4 +54,4 @@ describe Admin::ExportController do
end
end
end
end
end

View File

@ -23,10 +23,10 @@ describe Admin::FlagsController do
it 'returns a valid json payload when some thing is flagged' do
p = Fabricate(:post)
u = Fabricate(:user)
PostAction.act(u, p, PostActionType.Types[:spam])
xhr :get, :index
data = ::JSON.parse(response.body)
data["users"].length == 2
data["posts"].length == 1
@ -34,4 +34,4 @@ describe Admin::FlagsController do
end
end
end

View File

@ -50,12 +50,12 @@ describe Admin::ImpersonateController do
it "also works with an email address" do
xhr :post, :create, username_or_email: user.email
session[:current_user_id].should == user.id
end
end
it "also works with a name" do
xhr :post, :create, username_or_email: user.name
session[:current_user_id].should == user.id
end
end
end

View File

@ -20,16 +20,16 @@ describe Admin::SiteCustomizationsController do
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
end
end
end
context ' .create' do
it 'returns success' do
it 'returns success' do
xhr :post, :create, site_customization: {name: 'my test name'}
response.should be_success
end
it 'returns json' do
it 'returns json' do
xhr :post, :create, site_customization: {name: 'my test name'}
::JSON.parse(response.body).should be_present
end

View File

@ -20,7 +20,7 @@ describe Admin::SiteSettingsController do
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
end
end
end
context 'update' do
@ -40,4 +40,4 @@ describe Admin::SiteSettingsController do
end
end

View File

@ -20,7 +20,7 @@ describe Admin::UsersController do
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
end
end
end
context '.show' do
@ -81,7 +81,7 @@ describe Admin::UsersController do
response.should be_forbidden
end
it 'updates the admin flag' do
it 'updates the admin flag' do
xhr :put, :revoke_admin, user_id: @another_admin.id
@another_admin.reload
@another_admin.should_not be_admin
@ -99,12 +99,12 @@ describe Admin::UsersController do
response.should be_forbidden
end
it "returns a 404 if the username doesn't exist" do
it "returns a 404 if the username doesn't exist" do
xhr :put, :grant_admin, user_id: 123123
response.should be_forbidden
end
it 'updates the admin flag' do
it 'updates the admin flag' do
xhr :put, :grant_admin, user_id: @another_user.id
@another_user.reload
@another_user.should be_admin
@ -122,7 +122,7 @@ describe Admin::UsersController do
response.should be_forbidden
end
it 'updates the moderator flag' do
it 'updates the moderator flag' do
xhr :put, :revoke_moderation, user_id: @moderator.id
@moderator.reload
@moderator.has_trust_level?(:moderator).should_not be_true
@ -140,12 +140,12 @@ describe Admin::UsersController do
response.should be_forbidden
end
it "returns a 404 if the username doesn't exist" do
it "returns a 404 if the username doesn't exist" do
xhr :put, :grant_moderation, user_id: 123123
response.should be_forbidden
end
it 'updates the moderator flag' do
it 'updates the moderator flag' do
xhr :put, :grant_moderation, user_id: @another_user.id
@another_user.reload
@another_user.has_trust_level?(:moderator).should be_true

View File

@ -65,19 +65,19 @@ describe CategoriesController do
describe 'logged in' do
before do
@user = log_in
@category = Fabricate(:category, user: @user)
@category = Fabricate(:category, user: @user)
end
it "raises an exception if they don't have permission to delete it" do
Guardian.any_instance.expects(:can_delete_category?).returns(false)
xhr :delete, :destroy, id: @category.slug
response.should be_forbidden
end
end
it "deletes the record" do
Guardian.any_instance.expects(:can_delete_category?).returns(true)
lambda { xhr :delete, :destroy, id: @category.slug}.should change(Category, :count).by(-1)
end
end
end
end
@ -90,7 +90,7 @@ describe CategoriesController do
describe 'logged in' do
before do
before do
@user = log_in(:moderator)
@category = Fabricate(:category, user: @user)
end
@ -101,11 +101,11 @@ describe CategoriesController do
response.should be_forbidden
end
it "requires a name" do
it "requires a name" do
lambda { xhr :put, :update, id: @category.slug, color: '#fff' }.should raise_error(Discourse::InvalidParameters)
end
it "requires a color" do
it "requires a color" do
lambda { xhr :put, :update, id: @category.slug, name: 'asdf'}.should raise_error(Discourse::InvalidParameters)
end

View File

@ -25,19 +25,19 @@ describe ClicksController do
context 'with a post_id' do
it 'calls create_from' do
TopicLinkClick.expects(:create_from).with(url: 'http://discourse.org', post_id: 123, ip: '192.168.0.1')
xhr :get, :track, url: 'http://discourse.org', post_id: 123
xhr :get, :track, url: 'http://discourse.org', post_id: 123
response.should redirect_to("http://discourse.org")
end
it 'redirects to the url' do
TopicLinkClick.stubs(:create_from)
xhr :get, :track, url: 'http://discourse.org', post_id: 123
xhr :get, :track, url: 'http://discourse.org', post_id: 123
response.should redirect_to("http://discourse.org")
end
it 'will pass the user_id to create_from' do
TopicLinkClick.expects(:create_from).with(url: 'http://discourse.org', post_id: 123, ip: '192.168.0.1')
xhr :get, :track, url: 'http://discourse.org', post_id: 123
xhr :get, :track, url: 'http://discourse.org', post_id: 123
response.should redirect_to("http://discourse.org")
end
@ -52,13 +52,13 @@ describe ClicksController do
context 'with a topic_id' do
it 'calls create_from' do
TopicLinkClick.expects(:create_from).with(url: 'http://discourse.org', topic_id: 789, ip: '192.168.0.1')
xhr :get, :track, url: 'http://discourse.org', topic_id: 789
xhr :get, :track, url: 'http://discourse.org', topic_id: 789
response.should redirect_to("http://discourse.org")
end
end
end
end
end
end
end

View File

@ -12,11 +12,11 @@ describe DraftController do
Draft.get(user, 'xyz', 0).should == 'my data'
end
it 'destroys drafts when required' do
it 'destroys drafts when required' do
user = log_in
Draft.set(user, 'xxx', 0, 'hi')
delete :destroy, draft_key: 'xxx', sequence: 0
Draft.get(user, 'xxx', 0).should be_nil
end
end

View File

@ -21,7 +21,7 @@ describe EducationController do
end
context 'with a valid id' do
let(:markdown_content) { "Education *markdown* content" }
let(:html_content) {"HTML Content"}

View File

@ -69,7 +69,7 @@ describe EmailController do
it 'sets not found' do
assigns(:not_found).should be_true
end
end
end
context 'when logged in as the keyed user' do
@ -86,7 +86,7 @@ describe EmailController do
it "doesn't set not found" do
assigns(:not_found).should be_blank
end
end
end
it "sets not_found when the key didn't match anything" do

View File

@ -25,7 +25,7 @@ describe ExcerptController do
xhr :get, :show, url: @url
end
it 'returns a valid status' do
it 'returns a valid status' do
response.should be_success
end
@ -44,7 +44,7 @@ describe ExcerptController do
xhr :get, :show, url: @url
end
it 'returns a valid status' do
it 'returns a valid status' do
response.should be_success
end
@ -63,7 +63,7 @@ describe ExcerptController do
xhr :get, :show, url: @url
end
it 'returns a valid status' do
it 'returns a valid status' do
response.should be_success
end

View File

@ -10,11 +10,11 @@ describe InvitesController do
}.should raise_error(Discourse::NotLoggedIn)
end
context 'while logged in' do
context 'while logged in' do
let!(:user) { log_in }
let!(:invite) { Fabricate(:invite, invited_by: user) }
let(:another_invite) { Fabricate(:invite, email: 'anotheremail@address.com') }
it 'raises an error when the email is missing' do
lambda { delete :destroy }.should raise_error(Discourse::InvalidParameters)
@ -46,13 +46,13 @@ describe InvitesController do
get :show, id: "doesn't exist"
end
it "redirects to the root" do
it "redirects to the root" do
response.should redirect_to("/")
end
end
it "should not change the session" do
it "should not change the session" do
session[:current_user_id].should be_blank
end
end
end
@ -64,13 +64,13 @@ describe InvitesController do
get :show, id: deleted_invite.invite_key
end
it "redirects to the root" do
it "redirects to the root" do
response.should redirect_to("/")
end
end
it "should not change the session" do
it "should not change the session" do
session[:current_user_id].should be_blank
end
end
end
@ -78,7 +78,7 @@ describe InvitesController do
context 'with a valid invite id' do
let(:topic) { Fabricate(:topic) }
let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") }
it 'redeems the invite' do
Invite.any_instance.expects(:redeem)
@ -88,10 +88,10 @@ describe InvitesController do
context 'when redeem returns a user' do
let(:user) { Fabricate(:coding_horror) }
context 'success' do
context 'success' do
before do
Invite.any_instance.expects(:redeem).returns(user)
get :show, id: invite.invite_key
get :show, id: invite.invite_key
end
it 'logs in the user' do
@ -109,13 +109,13 @@ describe InvitesController do
Jobs.expects(:enqueue).with(:invite_email, has_key(:invite_id))
end
it 'sends a welcome message if set' do
user.send_welcome_message = true
it 'sends a welcome message if set' do
user.send_welcome_message = true
user.expects(:enqueue_welcome_message).with('welcome_invite')
get :show, id: invite.invite_key
end
it "doesn't send a welcome message if not set" do
it "doesn't send a welcome message if not set" do
user.expects(:enqueue_welcome_message).with('welcome_invite').never
get :show, id: invite.invite_key
end
@ -137,11 +137,11 @@ describe InvitesController do
Invite.any_instance.expects(:redeem).returns(user)
get :show, id: invite.invite_key
cookies[:_access].should == 'adventure time!'
end
end
end
end
end
end
end

View File

@ -2,8 +2,8 @@ require 'spec_helper'
describe ListController do
# we need some data
before do
# we need some data
before do
@user = Fabricate(:coding_horror)
@post = Fabricate(:post, :user => @user)
end

View File

@ -5,7 +5,7 @@ describe NotificationsController do
context 'when logged in' do
let!(:user) { log_in }
before do
before do
xhr :get, :index
end
@ -16,7 +16,7 @@ describe NotificationsController do
context 'when not logged in' do
it 'should raise an error' do
lambda { xhr :get, :index }.should raise_error(Discourse::NotLoggedIn)
end
end
end
end

View File

@ -20,7 +20,7 @@ describe PostActionsController do
it 'raises an error when the post_action_type_id index is missing' do
lambda { xhr :post, :create, id: @post.id }.should raise_error(Discourse::InvalidParameters)
end
it "fails when the user doesn't have permission to see the post" do
Guardian.any_instance.expects(:can_see?).with(@post).returns(false)
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.Types[:like]
@ -92,7 +92,7 @@ describe PostActionsController do
context "not logged in" do
it "should not allow them to clear flags" do
lambda { xhr :post, :clear_flags }.should raise_error(Discourse::NotLoggedIn)
end
end
end
context 'logged in' do
@ -103,21 +103,21 @@ describe PostActionsController do
end
it "raises an error when the user doesn't have access" do
Guardian.any_instance.expects(:can_clear_flags?).returns(false)
Guardian.any_instance.expects(:can_clear_flags?).returns(false)
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
response.should be_forbidden
end
context "success" do
before do
Guardian.any_instance.expects(:can_clear_flags?).returns(true)
Guardian.any_instance.expects(:can_clear_flags?).returns(true)
PostAction.expects(:clear_flags!).with(flagged_post, user.id, PostActionType.Types[:spam])
end
it "delegates to clear_flags" do
it "delegates to clear_flags" do
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
response.should be_success
end
end
it "works with a deleted post" do
flagged_post.destroy
@ -163,7 +163,7 @@ describe PostActionsController do
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.Types[:like]
response.should be_forbidden
end
it 'succeeds' do
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.Types[:like]
response.should be_success

View File

@ -24,18 +24,18 @@ describe PostsController do
post.destroy
end
it "can't find deleted posts as an anonymous user" do
it "can't find deleted posts as an anonymous user" do
xhr :get, :show, id: post.id
response.should be_forbidden
end
it "can't find deleted posts as a regular user" do
it "can't find deleted posts as a regular user" do
log_in(:user)
xhr :get, :show, id: post.id
response.should be_forbidden
end
it "can find posts as a moderator" do
it "can find posts as a moderator" do
log_in(:moderator)
xhr :get, :show, id: post.id
response.should be_success
@ -121,7 +121,7 @@ describe PostsController do
describe 'destroy_many' do
it 'raises an exception when not logged in' do
lambda { xhr :delete, :destroy_many, post_ids: [123, 345] }.should raise_error(Discourse::NotLoggedIn)
end
end
describe 'when logged in' do
@ -168,7 +168,7 @@ describe PostsController do
let(:post) { Fabricate(:post, user: log_in) }
let(:update_params) do
{id: post.id,
{id: post.id,
post: {raw: 'edited body'},
image_sizes: {'http://image.com/image.jpg' => {'width' => 123, 'height' => 456}}}
end
@ -180,7 +180,7 @@ describe PostsController do
it "raises an error when the post parameter is missing" do
update_params.delete(:post)
lambda {
lambda {
xhr :put, :update, update_params
}.should raise_error(Discourse::InvalidParameters)
end
@ -217,7 +217,7 @@ describe PostsController do
it "raises an error if the user doesn't have permission to see the post" do
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
xhr :put, :bookmark, post_id: post.id, bookmarked: 'true'
xhr :put, :bookmark, post_id: post.id, bookmarked: 'true'
response.should be_forbidden
end
@ -278,7 +278,7 @@ describe PostsController do
it "passes title through" do
PostCreator.expects(:new).with(user, has_entries(title: 'new topic title')).returns(post_creator)
xhr :post, :create, post: {raw: 'hello'}, title: 'new topic title'
xhr :post, :create, post: {raw: 'hello'}, title: 'new topic title'
end
it "passes topic_id through" do
@ -293,12 +293,12 @@ describe PostsController do
it "passes category through" do
PostCreator.expects(:new).with(user, has_entries(category: 'cool')).returns(post_creator)
xhr :post, :create, post: {raw: 'hello', category: 'cool'}
xhr :post, :create, post: {raw: 'hello', category: 'cool'}
end
it "passes target_usernames through" do
PostCreator.expects(:new).with(user, has_entries(target_usernames: 'evil,trout')).returns(post_creator)
xhr :post, :create, post: {raw: 'hello'}, target_usernames: 'evil,trout'
xhr :post, :create, post: {raw: 'hello'}, target_usernames: 'evil,trout'
end
it "passes reply_to_post_number through" do
@ -309,12 +309,12 @@ describe PostsController do
it "passes image_sizes through" do
PostCreator.expects(:new).with(user, has_entries(image_sizes: 'test')).returns(post_creator)
xhr :post, :create, post: {raw: 'hello'}, image_sizes: 'test'
end
end
it "passes meta_data through" do
PostCreator.expects(:new).with(user, has_entries(meta_data: {'xyz' => 'abc'})).returns(post_creator)
xhr :post, :create, post: {raw: 'hello'}, meta_data: {xyz: 'abc'}
end
end
end

View File

@ -11,7 +11,7 @@ describe RequestAccessController do
it "assigns the return path we provide" do
get :new, return_path: '/asdf'
assigns(:return_path).should == "/asdf"
end
end
end
@ -43,7 +43,7 @@ describe RequestAccessController do
it 'redirects to the return path' do
response.should redirect_to('/the-path')
end
end
it 'sets no flash error' do
flash[:error].should be_blank

View File

@ -10,13 +10,13 @@ describe RobotsTxtController do
response.should render_template :index
end
it "returns noindex when indexing is disallowed" do
it "returns noindex when indexing is disallowed" do
SiteSetting.stubs(:allow_index_in_robots_txt).returns(false)
get :index
response.should render_template :no_index
end
it "serves noindex when in private mode regardless of the configuration" do
end
it "serves noindex when in private mode regardless of the configuration" do
SiteSetting.stubs(:allow_index_in_robots_txt).returns(true)
SiteSetting.stubs(:restrict_access).returns(true)
get :index

View File

@ -118,28 +118,28 @@ describe SessionController do
end
context 'for a non existant username' do
it "doesn't generate a new token for a made up username" do
it "doesn't generate a new token for a made up username" do
lambda { xhr :post, :forgot_password, username: 'made_up'}.should_not change(EmailToken, :count)
end
it "doesn't enqueue an email" do
it "doesn't enqueue an email" do
Jobs.expects(:enqueue).with(:user_mail, anything).never
xhr :post, :forgot_password, username: 'made_up'
end
end
end
end
context 'for an existing username' do
let(:user) { Fabricate(:user) }
it "generates a new token for a made up username" do
it "generates a new token for a made up username" do
lambda { xhr :post, :forgot_password, username: user.username}.should change(EmailToken, :count)
end
it "enqueues an email" do
it "enqueues an email" do
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :forgot_password, user_id: user.id))
xhr :post, :forgot_password, username: user.username
end
end
end
end
end

View File

@ -8,7 +8,7 @@ describe StaticController do
xhr :get, :show, :id => 'faq'
end
it 'renders the static file if present' do
it 'renders the static file if present' do
response.should be_success
end

View File

@ -44,7 +44,7 @@ describe TopicsController do
it "has a url" do
::JSON.parse(response.body)['url'].should be_present
end
end
end
context 'failure' do
@ -67,7 +67,7 @@ describe TopicsController do
::JSON.parse(response.body)['url'].should be_blank
end
end
end
end
@ -96,7 +96,7 @@ describe TopicsController do
end
it 'requires the enabled parameter' do
lambda { xhr :put, :status, topic_id: @topic.id, status: 'visible' }.should raise_error(Discourse::InvalidParameters)
lambda { xhr :put, :status, topic_id: @topic.id, status: 'visible' }.should raise_error(Discourse::InvalidParameters)
end
it 'raises an error with a status not in the whitelist' do
@ -132,7 +132,7 @@ describe TopicsController do
it 'deletes the forum topic user record' do
PostTiming.expects(:destroy_for).with(@user.id, @topic.id)
xhr :delete, :destroy_timings, topic_id: @topic.id
xhr :delete, :destroy_timings, topic_id: @topic.id
end
end
@ -140,7 +140,7 @@ describe TopicsController do
end
describe 'mute/unmute' do
describe 'mute/unmute' do
it 'needs you to be logged in' do
lambda { xhr :put, :mute, topic_id: 99}.should raise_error(Discourse::NotLoggedIn)
@ -150,7 +150,7 @@ describe TopicsController do
lambda { xhr :put, :unmute, topic_id: 99}.should raise_error(Discourse::NotLoggedIn)
end
describe 'when logged in' do
describe 'when logged in' do
before do
@topic = Fabricate(:topic, user: log_in)
end
@ -158,12 +158,12 @@ describe TopicsController do
it "changes the user's starred flag when the parameter is present" do
Topic.any_instance.expects(:toggle_mute).with(@topic.user, true)
xhr :put, :mute, topic_id: @topic.id, starred: 'true'
end
end
it "removes the user's starred flag when the parameter is not true" do
Topic.any_instance.expects(:toggle_mute).with(@topic.user, false)
xhr :put, :unmute, topic_id: @topic.id, starred: 'false'
end
end
end
@ -182,20 +182,20 @@ describe TopicsController do
it "ensures the user can see the topic" do
Guardian.any_instance.expects(:can_see?).with(@topic).returns(false)
xhr :put, :star, topic_id: @topic.id, starred: 'true'
xhr :put, :star, topic_id: @topic.id, starred: 'true'
response.should be_forbidden
end
it "changes the user's starred flag when the parameter is present" do
Topic.any_instance.expects(:toggle_star).with(@topic.user, true)
xhr :put, :star, topic_id: @topic.id, starred: 'true'
end
end
it "removes the user's starred flag when the parameter is not true" do
Topic.any_instance.expects(:toggle_star).with(@topic.user, false)
xhr :put, :star, topic_id: @topic.id, starred: 'false'
end
end
end
end
end
describe 'delete' do
@ -213,7 +213,7 @@ describe TopicsController do
Guardian.any_instance.expects(:can_delete?).with(@topic).returns(false)
xhr :delete, :destroy, id: @topic.id
response.should be_forbidden
end
end
end
describe 'with permission' do
@ -236,7 +236,7 @@ describe TopicsController do
end
end
describe 'show' do
describe 'show' do
let(:topic) { Fabricate(:post).topic }
let!(:p1) { Fabricate(:post, user: topic.user) }
@ -251,7 +251,7 @@ describe TopicsController do
lambda { xhr :get, :show, id: topic.id }.should change(View, :count).by(1)
end
it 'tracks a visit for all html requests' do
it 'tracks a visit for all html requests' do
current_user = log_in(:coding_horror)
TopicUser.expects(:track_visit!).with(topic, current_user)
get :show, id: topic.id
@ -293,7 +293,7 @@ describe TopicsController do
it 'delegates a posts_before param to TopicView#filter_posts_before' do
TopicView.any_instance.expects(:filter_posts_before).with(p2.post_number)
xhr :get, :show, id: topic.id, posts_before: p2.post_number
end
end
end
@ -314,7 +314,7 @@ describe TopicsController do
Guardian.any_instance.expects(:can_edit?).with(@topic).returns(false)
xhr :put, :update, topic_id: @topic.id, slug: @topic.title
response.should be_forbidden
end
end
end
describe 'with permission' do
@ -345,7 +345,7 @@ describe TopicsController do
describe 'invite' do
it "won't allow us to invite toa topic when we're not logged in" do
lambda { xhr :post, :invite, topic_id: 1, email: 'jake@adventuretime.ooo' }.should raise_error(Discourse::NotLoggedIn)
end
end
describe 'when logged in' do
before do
@ -361,7 +361,7 @@ describe TopicsController do
Guardian.any_instance.expects(:can_invite_to?).with(@topic).returns(false)
xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo'
response.should be_forbidden
end
end
end
describe 'with permission' do
@ -382,7 +382,7 @@ describe TopicsController do
it 'returns success JSON' do
::JSON.parse(response.body).should == {'success' => 'OK'}
end
end
end
context 'when it fails and returns nil' do
@ -398,7 +398,7 @@ describe TopicsController do
it 'returns success JSON' do
::JSON.parse(response.body).should == {'failed' => 'FAILED'}
end
end
end