Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set trait for user factory

  • Loading branch information...
commit 5d2c257a4aa7eb974dc49da12f3627487b99031a 1 parent 51e4a5b
@yaf yaf authored
View
1  app/controllers/admin/content_controller.rb
@@ -9,7 +9,6 @@ class Admin::ContentController < Admin::BaseController
def auto_complete_for_article_keywords
@items = Tag.find(:all, select: :display_name, order: :display_name).map {|t| t.display_name}
-
render inline: "<%= @items %>"
end
View
36 spec/controllers/accounts_controller_spec.rb
@@ -3,9 +3,9 @@
describe AccountsController do
describe "A successful login with 'Remember me' checked" do
it 'should not cause password to change' do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:salt).and_return('change-me')
- henri = FactoryGirl.create(:user, :login => 'henri', :password => 'testagain')
+ henri = create(:user, :login => 'henri', :password => 'testagain')
post 'login', {:user => {:login => 'henri', :password => 'testagain'}, :remember_me => '1'}
request.session[:user_id].should == henri.id
end
@@ -13,9 +13,9 @@
describe 'A successfully authenticated login' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:salt).and_return('change-me')
- @henri = FactoryGirl.create(:user, :login => 'henri', :password => 'testagain', :profile => FactoryGirl.create(:profile_admin, :label => 'admin_henri'))
+ @henri = create(:user, :login => 'henri', :password => 'testagain', :profile => create(:profile_admin, :label => 'admin_henri'))
end
def make_request
@@ -58,7 +58,7 @@ def make_request
describe 'User is inactive' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:authenticate).and_return(nil)
User.stub(:count).and_return(1)
end
@@ -91,7 +91,7 @@ def make_request
describe 'Login with nil user and password' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:count).and_return(1)
end
@@ -107,7 +107,7 @@ def make_request
describe 'Login gets the wrong password' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:authenticate).and_return(nil)
User.stub(:count).and_return(1)
end
@@ -138,15 +138,15 @@ def make_request
end
describe 'GET /index' do
+ let!(:blog) { create(:blog) }
+
it 'should redirect to login' do
- FactoryGirl.create(:blog)
User.stub(:count).and_return(1)
get 'index'
response.should redirect_to(:action => 'login')
end
it 'should redirect to signup' do
- FactoryGirl.create(:blog)
User.stub(:count).and_return(0)
get 'index'
response.should redirect_to(:action => 'signup')
@@ -155,7 +155,7 @@ def make_request
describe 'GET /login' do
it 'should render action :login' do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:count).and_return(1)
get 'login'
response.should render_template(:login)
@@ -165,7 +165,7 @@ def make_request
describe 'GET /login with 0 existing users' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:count).and_return(0)
end
@@ -183,7 +183,7 @@ def make_request
describe 'with >0 existing user and allow_signup = 0' do
before(:each) do
- @blog = FactoryGirl.create(:blog)
+ @blog = create(:blog)
User.stub(:count).and_return(1)
end
@@ -204,7 +204,7 @@ def make_request
describe 'with > 0 existing user and allow_signup = 1' do
before(:each) do
- @blog = FactoryGirl.create(:blog, :allow_signup => 1)
+ @blog = create(:blog, :allow_signup => 1)
User.stub(:count).and_return(1)
end
@@ -225,7 +225,7 @@ def make_request
end
describe 'GET signup with 0 existing users' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:count).and_return(0)
@user = double("user")
@user.stub(:reload).and_return(@user)
@@ -286,7 +286,7 @@ def make_request
describe 'POST signup with 0 existing users' do
before(:each) do
- FactoryGirl.create(:blog)
+ create(:blog)
User.stub(:count).and_return(0)
@user = mock_model(User)
@user.stub(:login).and_return('newbob')
@@ -322,8 +322,8 @@ def params
describe 'User is logged in' do
before(:each) do
- FactoryGirl.create(:blog)
- @user = FactoryGirl.create(:user)
+ create(:blog)
+ @user = create(:user)
# The AccountsController class uses session[:user_id], and the
# Publify LoginSystem uses session[:user]. So we need to set both of
@@ -365,7 +365,7 @@ def params
describe :recover_password do
let!(:blog) { create(:blog) }
- let!(:user) { create(:user_admin) }
+ let!(:user) { create(:user, :as_admin) }
context "simply get" do
before(:each) { get :recover_password }
View
2  spec/controllers/admin/cache_controller_spec.rb
@@ -5,7 +5,7 @@
let!(:blog) { create(:blog) }
before(:each) do
- admin = create(:user_admin)
+ admin = create(:user, :as_admin)
request.session = { user: admin.id }
end
View
38 spec/controllers/admin/content_controller_spec.rb
@@ -88,16 +88,16 @@
it 'should save new article with draft status and no parent article' do
create(:none)
lambda do
- lambda do
- xhr :post, :autosave, :article => {:allow_comments => '1',
- :body_and_extended => 'my draft in autosave',
- :keywords => 'mientag',
- :permalink => 'big-post',
- :title => 'big post',
- :text_filter => 'none',
- :published => '1',
- :published_at => 'December 23, 2009 03:20 PM'}
- end.should change(Article, :count)
+ lambda do
+ xhr :post, :autosave, :article => {:allow_comments => '1',
+ :body_and_extended => 'my draft in autosave',
+ :keywords => 'mientag',
+ :permalink => 'big-post',
+ :title => 'big post',
+ :text_filter => 'none',
+ :published => '1',
+ :published_at => 'December 23, 2009 03:20 PM'}
+ end.should change(Article, :count)
end.should change(Tag, :count)
result = Article.last
result.body.should == 'my draft in autosave'
@@ -128,13 +128,13 @@
before(:each) do
data = {:allow_comments => article.allow_comments,
- :body_and_extended => 'my draft in autosave',
- :keywords => '',
- :permalink => article.permalink,
- :title => article.title,
- :text_filter => article.text_filter,
- :published => '1',
- :published_at => 'December 23, 2009 03:20 PM'}
+ :body_and_extended => 'my draft in autosave',
+ :keywords => '',
+ :permalink => article.permalink,
+ :title => article.title,
+ :text_filter => article.text_filter,
+ :published => '1',
+ :published_at => 'December 23, 2009 03:20 PM'}
xhr :post, :autosave, id: article.id, article: data
end
@@ -321,9 +321,9 @@ def base_article(options={})
describe 'with admin connection' do
before(:each) do
- @user = create(:user_admin, text_filter: create(:markdown))
- @article = create(:article)
+ @user = create(:user, :as_admin, text_filter: create(:markdown))
request.session = { :user => @user.id }
+ @article = create(:article)
end
it_should_behave_like 'index action'
View
4 spec/controllers/admin/notes_controller_spec.rb
@@ -6,7 +6,7 @@
before(:each) { request.session = { user: admin.id } }
context "with a blog" do
- let(:admin) { create(:user_admin) }
+ let(:admin) { create(:user, :as_admin) }
let!(:blog) { create(:blog) }
describe :index do
@@ -63,7 +63,7 @@
context "with a blog with twitter configured" do
let!(:blog) { create(:blog_with_twitter) }
- let(:admin) { create(:user_admin, :with_twitter) }
+ let(:admin) { create(:user, :as_admin, :with_twitter) }
describe :edit do
context "when push to twitter" do
View
2  spec/controllers/admin/pages_controller_spec.rb
@@ -5,7 +5,7 @@
render_views
let!(:blog) { create(:blog) }
- let!(:user) { create(:user_admin) }
+ let!(:user) { create(:user, :as_admin) }
before(:each) { request.session = { user: user.id } }
View
2  spec/controllers/admin/settings_controller_spec.rb
@@ -5,7 +5,7 @@
before(:each) do
create(:blog)
- alice = create(:user_admin, :login => 'alice')
+ alice = create(:user, :as_admin, login: 'alice')
request.session = { :user => alice.id }
end
View
4 spec/controllers/articles_controller_spec.rb
@@ -281,7 +281,7 @@
end
describe 'with logged user' do
- let(:admin) { create(:user_admin) }
+ let(:admin) { create(:user, :as_admin) }
let(:article) { create(:article, user: admin) }
before(:each) { @request.session = { user: admin.id } }
@@ -407,7 +407,7 @@
describe 'with permalink_format like %title%.html' do
let!(:blog) { create(:blog, :permalink_format => '/%title%.html') }
- let!(:admin) { create(:user_admin) }
+ let!(:admin) { create(:user, :as_admin) }
before(:each) do
@request.session = { :user => admin.id }
View
4 spec/controllers/author_controller_spec.rb
@@ -6,7 +6,7 @@
describe :show do
describe "With an empty profile" do
- let(:no_profile_user) { create(:user_with_an_empty_profile) }
+ let(:no_profile_user) { create(:user, :without_twitter) }
let!(:article) { create(:article, user: no_profile_user, published_at: now - 1.hour) }
describe "html" do
@@ -35,7 +35,7 @@
end
describe "With full profile" do
- let!(:full_profile_user) { create(:user_with_a_full_profile) }
+ let!(:full_profile_user) { create(:user, :with_a_full_profile) }
let!(:article) { create(:article, user: full_profile_user) }
describe "html" do
View
21 spec/factories.rb
@@ -27,14 +27,12 @@
association :resource, factory: :avatar
association :text_filter, factory: :textile
- factory :user_with_an_empty_profile do
- name "Doe"
- nickname "John Doe"
+ trait :without_twitter do
twitter nil
association :resource, nil
end
- factory :user_with_a_full_profile do
+ trait :with_a_full_profile do
description "I am a poor lonesone factory generated user"
url "http://myblog.net"
msn "random@mail.com"
@@ -44,14 +42,19 @@
jabber "random@account.com"
end
- factory :user_admin do
+ trait :with_twitter do
+ twitter_oauth_token "oauth_token"
+ twitter_oauth_token_secret "oauth_token"
+ end
+
+ trait :as_admin do
association :profile, factory: :profile_admin
+ end
- trait :with_twitter do
- twitter_oauth_token "oauth_token"
- twitter_oauth_token_secret "oauth_token"
- end
+ trait :as_publisher do
+ association :profile, factory: :profile_publisher
end
+
end
factory :article do
Please sign in to comment.
Something went wrong with that request. Please try again.