diff --git a/db/seeds.rb b/db/seeds.rb index ac2a141d..6f4f9d35 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,56 +1,43 @@ -#encoding: UTF-8 -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) - - +# encoding: UTF-8 require 'factory_girl_rails' - +puts "seeding data... this process can take 20-25 minutes" Administrator.find_or_create_by_email({ email: "admin@avoinministerio.fi", password: "hallinta" }) - [ { email: "joonas@pekkanen.com", password: "joonas1", password_confirmation: "joonas1", remember_me: true, profile_attributes: {first_names: "Joonas", first_name: "Joonas", last_name: "Pekkanen", name: "Joonas Pekkanen"}, }, - + { email: "arttu.tervo@gmail.com", password: "arttu1", password_confirmation: "arttu1", remember_me: true, profile_attributes: {first_names: "Arttu", first_name: "Arttu", last_name: "Tervo", name: "Arttu Tervo"}, }, - + { email: "aleksi.rossi@iki.fi", password: "aleksi1", password_confirmation: "aleksi1", remember_me: true, profile_attributes: {first_names: "Aleksi", first_name: "Aleksi", last_name: "Rossi", name: "Aleksi Rossi"}, }, - + { email: "hleinone@gmail.com", password: "hannu1", password_confirmation: "hannu1", remember_me: true, profile_attributes: {first_names: "Hannu", first_name: "Hannu", last_name: "Leinonen", name: "Hannu Leinonen"}, }, - + { email: "juha.yrjola@iki.fi", password: "juhay1", password_confirmation: "juhay1", remember_me: true, profile_attributes: {first_names: "Juha", first_name: "Juha", last_name: "Yrjölä", name: "Juha Yrjölä"}, }, - + { email: "lauri@kiskolabs.com", password: "lauri1", password_confirmation: "lauri1", remember_me: true, profile_attributes: {first_names: "Lauri", first_name: "Lauri", last_name: "Jutila", name: "Lauri Jutila"}, }, - + { email: "mikael.kopteff@gmail.com", password: "mikael1", password_confirmation: "mikael1", remember_me: true, profile_attributes: {first_names: "Mikael", first_name: "Mikael", last_name: "Kopteff", name: "Mikael Kopteff"}, }, ].each { |citizen| Citizen.find_or_create_by_email(citizen) } - @citizens = Citizen.all - def random_citizen @citizens[rand(@citizens.size)] end - joonas = Citizen.where(email: "joonas@pekkanen.com").first koiravero_body = < b}.each do |name| next unless File.file?(name) File.open(name) do |f| @@ -343,7 +315,6 @@ def field(f, name) ingress: field(f, "ingress") && read_till(f), body: field(f, "body") && read_till(f), } - Article.find_or_create_by_created_at(article) end end diff --git a/spec/acceptance/admin/articles_spec.rb b/spec/acceptance/admin/articles_spec.rb index bc51e4be..d2d43e0d 100644 --- a/spec/acceptance/admin/articles_spec.rb +++ b/spec/acceptance/admin/articles_spec.rb @@ -4,7 +4,7 @@ feature "Articles" do let (:idea) { - Factory :idea + FactoryGirl.create :idea } describe "PUT /articles" do before do diff --git a/spec/acceptance/citizen/existing_citizen_facebook_login_spec.rb b/spec/acceptance/citizen/existing_citizen_facebook_login_spec.rb index 0ca605fb..8dafe344 100644 --- a/spec/acceptance/citizen/existing_citizen_facebook_login_spec.rb +++ b/spec/acceptance/citizen/existing_citizen_facebook_login_spec.rb @@ -3,7 +3,7 @@ feature "Existing citizen logins in with Facebook" do background do - _citizen = Factory(:facebookin_erkki) + _citizen = FactoryGirl.create :facebookin_erkki mock_facebook_omniauth(_citizen.authentication.uid, email: _citizen.email) end diff --git a/spec/acceptance/citizen/signup_spec.rb b/spec/acceptance/citizen/signup_spec.rb index a71f2c10..b96a3a55 100644 --- a/spec/acceptance/citizen/signup_spec.rb +++ b/spec/acceptance/citizen/signup_spec.rb @@ -4,7 +4,7 @@ feature "Citizen Signup" do let(:password) { '123456789' } - let(:citizen) { Factory(:citizen, :password => '123456789', :password_confirmation => '123456789') } + let(:citizen) { FactoryGirl.create :citizen, :password => '123456789', :password_confirmation => '123456789' } scenario "Signup" do visit signup_page diff --git a/spec/acceptance/signing/idea_signing_2_spec.rb b/spec/acceptance/signing/idea_signing_2_spec.rb index b684bd06..803b5936 100644 --- a/spec/acceptance/signing/idea_signing_2_spec.rb +++ b/spec/acceptance/signing/idea_signing_2_spec.rb @@ -10,7 +10,7 @@ let(:citizen_password) { '123456789' } let(:citizen_email) { 'citizen-kane@example.com'} let(:idea) { - Factory :idea, state: "proposal", + FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: false, collecting_start_date: today_date, collecting_end_date: today_date + 180, @@ -19,7 +19,7 @@ additional_collecting_service_urls: "http://www.example.com/initiative" } let(:another_idea) { - Factory :idea, state: "proposal", + FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: false, collecting_start_date: today_date, collecting_end_date: today_date + 180, @@ -27,7 +27,7 @@ target_count: 51500 } let(:state_idea) { - Factory :idea, state: "idea", + FactoryGirl.create :idea, state: "idea", collecting_in_service: false, collecting_started: false, collecting_ended: false, collecting_start_date: today_date + 1, collecting_end_date: today_date + 181, @@ -35,7 +35,7 @@ target_count: 51500 } let(:state_draft) { - Factory :idea, state: "draft", + FactoryGirl.create :idea, state: "draft", collecting_in_service: false, collecting_started: false, collecting_ended: false, collecting_start_date: today_date + 1, collecting_end_date: today_date + 181, @@ -43,7 +43,7 @@ target_count: 51500 } let(:not_started_proposal) { - Factory :idea, state: "proposal", + FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: false, collecting_ended: false, collecting_start_date: today_date + 1, collecting_end_date: today_date + 181, @@ -51,7 +51,7 @@ target_count: 51500 } let(:ended_proposal) { - Factory :idea, state: "proposal", + FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: true, collecting_start_date: today_date - 181, collecting_end_date: today_date - 1, @@ -59,7 +59,7 @@ target_count: 51500 } let(:signature) { - Factory :signature, idea: idea + FactoryGirl.create :signature, idea: idea } context "Sign button on Idea page visible" do @@ -123,25 +123,25 @@ page.should have_content("Tällä tahdilla ei ehditä kerätä ilmoituksia riittävästi ennen päättymispäivää") end scenario "Idea is about to pass" do - idea_about_to_pass = Factory :idea, state: "proposal", + idea_about_to_pass = FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: false, collecting_start_date: today_date, collecting_end_date: today_date + 180, additional_signatures_count: 0, additional_signatures_count_date: today_date, target_count: 10 - signature_for_idea_about_to_pass = Factory :signature, idea: idea_about_to_pass + signature_for_idea_about_to_pass = FactoryGirl.create :signature, idea: idea_about_to_pass visit idea_page(idea_about_to_pass.id) page.should have_content("Tällä tahdilla ehditään kerätä ilmoitukset ennen päättymispäivää") end scenario "Idea has passed" do - passed_idea = Factory :idea, state: "proposal", + passed_idea = FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: false, collecting_start_date: today_date, collecting_end_date: today_date + 180, additional_signatures_count: 0, additional_signatures_count_date: today_date, target_count: 1 - signature_for_passed_idea = Factory :signature, idea: passed_idea + signature_for_passed_idea = FactoryGirl.create :signature, idea: passed_idea visit idea_page(passed_idea.id) page.should have_content("Tavoite on täyttynyt") diff --git a/spec/acceptance/signing/idea_signing_spec.rb b/spec/acceptance/signing/idea_signing_spec.rb index 78b3762b..8684644a 100644 --- a/spec/acceptance/signing/idea_signing_spec.rb +++ b/spec/acceptance/signing/idea_signing_spec.rb @@ -11,7 +11,7 @@ let(:citizen_password) { '123456789' } let(:citizen_email) { 'citizen-kane@example.com'} let(:idea) { - Factory :idea, state: "proposal", + FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: false, collecting_start_date: today_date, collecting_end_date: today_date + 180, @@ -19,7 +19,7 @@ target_count: 51500 } let(:another_idea) { - Factory :idea, state: "proposal", + FactoryGirl.create :idea, state: "proposal", collecting_in_service: true, collecting_started: true, collecting_ended: false, collecting_start_date: today_date, collecting_end_date: today_date + 180, @@ -636,14 +636,14 @@ def logged_in_citizen_on_homepage end scenario "the idea can't be signed and the citizen enters the URL manually" do - idea_that_cannot_be_signed = Factory :idea + idea_that_cannot_be_signed = FactoryGirl.create :idea visit signature_idea_introduction(idea_that_cannot_be_signed.id) page.should have_content "Can't be signed" page.should_not have_button "Siirry hyväksymään ehdot" end scenario "the idea can't be signed and the citizen attempts to enter the approval page directly" do - idea_that_cannot_be_signed = Factory :idea + idea_that_cannot_be_signed = FactoryGirl.create :idea page.driver.post(signature_idea_approval_path( idea_that_cannot_be_signed.id)) page.should have_content "Can't be signed" diff --git a/spec/acceptance/support/helpers.rb b/spec/acceptance/support/helpers.rb index b3580f52..1024a9c1 100644 --- a/spec/acceptance/support/helpers.rb +++ b/spec/acceptance/support/helpers.rb @@ -11,7 +11,7 @@ module HelperMethods # Put helper methods you need to be available in all acceptance specs here. def create_citizen(extra_attributes = {}) - Factory(:citizen, extra_attributes) + FactoryGirl.create :citizen, extra_attributes end def create_logged_in_citizen(extra_attributes = {}) @@ -25,7 +25,7 @@ def login_as_citizen(citizen) end def create_logged_in_administrator - administrator = Factory(:administrator) + administrator = FactoryGirl.create :administrator login_as_administrator(administrator) administrator end @@ -131,7 +131,7 @@ def mock_facebook_omniauth(uid = "1234567", info = {}) end def create_idea(extra_attributes = {}) - Factory(:idea, extra_attributes) + FactoryGirl.create :idea, extra_attributes end # This should be refactored somewhere away diff --git a/spec/controllers/admin/articles_controller_spec.rb b/spec/controllers/admin/articles_controller_spec.rb index ec7d4e59..946c76b7 100644 --- a/spec/controllers/admin/articles_controller_spec.rb +++ b/spec/controllers/admin/articles_controller_spec.rb @@ -13,10 +13,10 @@ describe Admin::ArticlesController do let (:administrator) { - Factory(:administrator) + FactoryGirl.create :administrator } let (:unsaved_article) { - Factory.build(:article) + FactoryGirl.build :article } let (:article_hash) {{ :article_type => unsaved_article.article_type, @@ -26,7 +26,7 @@ :idea_id => unsaved_article.idea.id }} let (:citizen) { - Factory(:citizen) + FactoryGirl.create :citizen } before :each do diff --git a/spec/controllers/admin/changelogs_controller_spec.rb b/spec/controllers/admin/changelogs_controller_spec.rb index 2a539467..856977d1 100644 --- a/spec/controllers/admin/changelogs_controller_spec.rb +++ b/spec/controllers/admin/changelogs_controller_spec.rb @@ -3,7 +3,7 @@ describe Admin::ChangelogsController do before :each do - @administrator = Factory(:administrator) + @administrator = FactoryGirl.create :administrator sign_in :administrator, @administrator end @@ -16,7 +16,7 @@ end it "shows changelogs" do - idea = Factory(:idea, :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.") + idea = FactoryGirl.create :idea, :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." idea.title = "Lorem ipsum dolor sit amet, ..." idea.save @@ -26,7 +26,7 @@ end it "shows short diffs" do - idea = Factory :idea, :body => <<-EOS + idea = FactoryGirl.create :idea, :body => <<-EOS Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris diff --git a/spec/controllers/admin/comments_controller_spec.rb b/spec/controllers/admin/comments_controller_spec.rb index ec063823..0f7e1a92 100644 --- a/spec/controllers/admin/comments_controller_spec.rb +++ b/spec/controllers/admin/comments_controller_spec.rb @@ -3,7 +3,7 @@ describe Admin::CommentsController do before :each do - @administrator = Factory(:administrator) + @administrator = FactoryGirl.create :administrator sign_in :administrator, @administrator end diff --git a/spec/controllers/admin/ideas_controller_spec.rb b/spec/controllers/admin/ideas_controller_spec.rb index 613d51d8..eec98ea2 100644 --- a/spec/controllers/admin/ideas_controller_spec.rb +++ b/spec/controllers/admin/ideas_controller_spec.rb @@ -3,7 +3,7 @@ describe Admin::IdeasController do before :each do - @administrator = Factory(:administrator) + @administrator = FactoryGirl.create :administrator sign_in :administrator, @administrator end diff --git a/spec/controllers/articles_controller_spec.rb b/spec/controllers/articles_controller_spec.rb index ea68be77..c79aaeee 100644 --- a/spec/controllers/articles_controller_spec.rb +++ b/spec/controllers/articles_controller_spec.rb @@ -5,7 +5,7 @@ describe "#show" do before :each do - @article = Factory :article + @article = FactoryGirl.create :article end it "should show an article" do diff --git a/spec/controllers/citizens/omniauth_callbacks_controller_spec.rb b/spec/controllers/citizens/omniauth_callbacks_controller_spec.rb index 43aa1900..77360b5c 100644 --- a/spec/controllers/citizens/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/citizens/omniauth_callbacks_controller_spec.rb @@ -3,7 +3,7 @@ describe Citizens::OmniauthCallbacksController do describe 'facebook' do it "should authenticate successfully" do - @citizen = Factory.create :facebookin_erkki + @citizen = FactoryGirl.create :facebookin_erkki request.env['omniauth.auth'] = auth_hash request.env["devise.mapping"] = Devise.mappings[:citizen] @@ -14,7 +14,7 @@ end it "should authenticate successfully and redirect to original page" do - @citizen = Factory.create :facebookin_erkki + @citizen = FactoryGirl.create :facebookin_erkki request.env['omniauth.auth'] = auth_hash request.env["devise.mapping"] = Devise.mappings[:citizen] diff --git a/spec/controllers/citizens_controller_spec.rb b/spec/controllers/citizens_controller_spec.rb index e18f1347..5e0d8250 100644 --- a/spec/controllers/citizens_controller_spec.rb +++ b/spec/controllers/citizens_controller_spec.rb @@ -2,7 +2,7 @@ describe CitizensController do let (:citizen) { - Factory :citizen + FactoryGirl.create :citizen } get :edit do diff --git a/spec/controllers/expert_suggestions_controller_spec.rb b/spec/controllers/expert_suggestions_controller_spec.rb index 5cc32fa3..68d7b59a 100644 --- a/spec/controllers/expert_suggestions_controller_spec.rb +++ b/spec/controllers/expert_suggestions_controller_spec.rb @@ -3,9 +3,9 @@ describe ExpertSuggestionsController do before :each do - @citizen = Factory.create :citizen + @citizen = FactoryGirl.create :citizen sign_in @citizen - @idea = Factory :idea + @idea = FactoryGirl.create :idea @valid_attributes = { firstname: 'Erkki', lastname: 'Esimerkki', diff --git a/spec/controllers/ideas_controller_spec.rb b/spec/controllers/ideas_controller_spec.rb index 849c0cb8..f816a1d4 100644 --- a/spec/controllers/ideas_controller_spec.rb +++ b/spec/controllers/ideas_controller_spec.rb @@ -9,7 +9,7 @@ describe "#show" do before :each do - @idea = Factory :idea + @idea = FactoryGirl.create :idea end it "should show an idea" do @@ -26,7 +26,7 @@ describe "logged in user" do before :each do - @citizen = Factory.create :citizen + @citizen = FactoryGirl.create :citizen sign_in @citizen end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index e7042868..cafd17ae 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -2,6 +2,9 @@ require 'spec_helper' describe PagesController do + before :each do + min_ideas_for_homepage + end describe "#home" do it "should be successful" do get :home @@ -10,8 +13,8 @@ describe "drafts section" do before :each do - @recent_draft = Factory(:idea, state: 'draft') - @recent_idea = Factory(:idea, state: 'idea') + @recent_draft = FactoryGirl.create(:idea, state: 'draft') + @recent_idea = FactoryGirl.create(:idea, state: 'idea') end it "should include only drafts to drafts section" do @@ -22,11 +25,11 @@ it "should calculate vote counts for a draft" do # 7 votes for and 4 votes against the idea - 7.times { Factory(:vote, idea: @recent_draft, option: 1) } - 4.times { Factory(:vote, idea: @recent_draft, option: 0) } + 7.times { FactoryGirl.create(:vote, idea: @recent_draft, option: 1) } + 4.times { FactoryGirl.create(:vote, idea: @recent_draft, option: 0) } # let's also create a draft without votes yet - voteless_draft = Factory(:idea, state: 'draft') + voteless_draft = FactoryGirl.create(:idea, state: 'draft') get :home @@ -37,8 +40,8 @@ describe "ideas section" do before :each do - @recent_idea = Factory(:idea, state: 'idea') - @recent_draft = Factory(:idea, state: 'draft') + @recent_idea = FactoryGirl.create(:idea, state: 'idea') + @recent_draft = FactoryGirl.create(:idea, state: 'draft') end it "should include only ideas in state 'idea' to ideas section" do @@ -49,11 +52,11 @@ it "should calculate vote counts for an idea" do # 1 vote for and 7 votes against the idea - 1.times { Factory(:vote, idea: @recent_idea, option: 1) } - 7.times { Factory(:vote, idea: @recent_idea, option: 0) } + 1.times { FactoryGirl.create(:vote, idea: @recent_idea, option: 1) } + 7.times { FactoryGirl.create(:vote, idea: @recent_idea, option: 0) } # let's also create an idea without votes yet - voteless_idea = Factory(:idea, state: 'idea') + voteless_idea = FactoryGirl.create(:idea, state: 'idea') get :home @@ -62,9 +65,9 @@ end it "should include comments count" do - 3.times { Factory(:comment, commentable: @recent_idea) } - another_idea = Factory(:idea, state: 'idea') - Factory(:comment, commentable: another_idea) + 3.times { FactoryGirl.create(:comment, commentable: @recent_idea) } + another_idea = FactoryGirl.create(:idea, state: 'idea') + FactoryGirl.create(:comment, commentable: another_idea) get :home @@ -77,7 +80,7 @@ render_views before :each do - @article = Factory(:article, article_type: 'blog') + @article = FactoryGirl.create(:article, article_type: 'blog') end it "should show a temporary text on home page when no there are no blog articles" do @@ -89,7 +92,7 @@ end it "should show articles with type = 'blog'" do - not_blog = Factory(:article, article_type: 'footer') + not_blog = FactoryGirl.create(:article, article_type: 'footer') get :home @@ -98,8 +101,8 @@ end it "should show only published blog articles" do - unpublished = Factory(:article, publish_state: 'unpublished') - moderated = Factory(:article, publish_state: 'in_moderation') + unpublished = FactoryGirl.create(:article, publish_state: 'unpublished') + moderated = FactoryGirl.create(:article, publish_state: 'in_moderation') get :home diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index e5340370..5055811b 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -2,7 +2,7 @@ describe ProfilesController do let (:citizen) { - Factory :citizen + FactoryGirl.create :citizen } get :edit do @@ -19,8 +19,8 @@ get :show do before do sign_in citizen - @vote = Factory :vote, :citizen => citizen - @comment = Factory :comment, :author => citizen + @vote = FactoryGirl.create :vote, :citizen => citizen + @comment = FactoryGirl.create :comment, :author => citizen end action! do it "adds a voted idea into @voted_ideas" do diff --git a/spec/controllers/signatures_controller_spec.rb b/spec/controllers/signatures_controller_spec.rb index 64a18137..8143798e 100644 --- a/spec/controllers/signatures_controller_spec.rb +++ b/spec/controllers/signatures_controller_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe SignaturesController do - let (:citizen) { Factory :citizen } - let (:idea) { Factory :idea } + let (:citizen) { FactoryGirl.create :citizen } + let (:idea) { FactoryGirl.create :idea } before do sign_in citizen @@ -17,8 +17,8 @@ describe "POST sign" do before do - @vote = Factory :vote, :citizen => citizen - @comment = Factory :comment, :author => citizen + @vote = FactoryGirl.create :vote, :citizen => citizen + @comment = FactoryGirl.create :comment, :author => citizen end it "assigns the newly created Signature as @signature" do diff --git a/spec/factories.rb b/spec/factories.rb index c40a4109..84b91b45 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -36,8 +36,8 @@ end factory :facebookin_erkki, parent: :erkki do |e| - after_create do |erkki| - Factory.create(:authentication, citizen: erkki) + after(:create) do |erkki| + FactoryGirl.create(:authentication, citizen: erkki) end end @@ -80,9 +80,9 @@ association :citizen, factory: :citizen association :idea, factory: :idea state 'signed' - accept_general 1 - accept_science 1 - accept_non_eu_server 1 + accept_general true + accept_science true + accept_non_eu_server true accept_publicity "Normal" end end diff --git a/spec/helpers/admin/changelogs_helper_spec.rb b/spec/helpers/admin/changelogs_helper_spec.rb index b86335b8..7532cd03 100644 --- a/spec/helpers/admin/changelogs_helper_spec.rb +++ b/spec/helpers/admin/changelogs_helper_spec.rb @@ -48,27 +48,27 @@ describe "#changelogged_link_for" do it "should build a link for an Idea" do - idea = Factory :idea + idea = FactoryGirl.create :idea link = helper.changelogged_link_for(idea.changelogs.last) link.should include("Idea ##{idea.id}") end it "should build a link for an Idea comment" do - idea = Factory :idea - comment = Factory :comment, commentable: idea + idea = FactoryGirl.create :idea + comment = FactoryGirl.create :comment, commentable: idea link = helper.changelogged_link_for(comment.changelogs.last) link.should include("Kommentti ##{comment.id}") end it "should build a link for an Article" do - article = Factory :article + article = FactoryGirl.create :article link = helper.changelogged_link_for(article.changelogs.last) link.should include("Artikkeli ##{article.id}") end it "should build a link for an Article comment" do - article = Factory :article - comment = Factory :comment, commentable: article + article = FactoryGirl.create :article + comment = FactoryGirl.create :comment, commentable: article link = helper.changelogged_link_for(comment.changelogs.last) link.should include("Kommentti ##{comment.id}") end diff --git a/spec/helpers/ideas_helper_spec.rb b/spec/helpers/ideas_helper_spec.rb index 6084265f..0e225f8a 100644 --- a/spec/helpers/ideas_helper_spec.rb +++ b/spec/helpers/ideas_helper_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' describe IdeasHelper do - let(:idea) { Factory(:idea) } + let(:idea) { FactoryGirl.create(:idea) } describe "#idea_state_image" do - let(:draft) { Factory(:idea, state: "draft") } - let(:proposal) { Factory(:idea, state: "proposal") } - let(:law) { Factory(:idea, state: "law") } + let(:draft) { FactoryGirl.create(:idea, state: "draft") } + let(:proposal) { FactoryGirl.create(:idea, state: "proposal") } + let(:law) { FactoryGirl.create(:idea, state: "law") } it "returns image tag for given idea and its state" do helper.idea_state_image(idea).should =~ /state_1_idea.png/ @@ -19,8 +19,8 @@ end describe "#vote_in_words" do - let(:citizen_0) { Factory(:citizen) } - let(:citizen_1) { Factory(:citizen) } + let(:citizen_0) { FactoryGirl.create(:citizen) } + let(:citizen_1) { FactoryGirl.create(:citizen) } before do idea.vote(citizen_0, 0) diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 0641f937..e9fc613a 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -4,7 +4,7 @@ it { should belong_to :author } it { should ensure_length_of(:title).is_at_least(5).with_short_message(/on liian lyhyt/) } - let(:article) { Factory(:article) } + let(:article) { FactoryGirl.create(:article) } it "should be valid" do article.should be_valid diff --git a/spec/models/citizen_spec.rb b/spec/models/citizen_spec.rb index 4b99f8ed..e3faf0fe 100644 --- a/spec/models/citizen_spec.rb +++ b/spec/models/citizen_spec.rb @@ -4,8 +4,8 @@ describe "#image" do context "with profile picture" do before do - profile = Factory(:profile, :image => "http://www.facebook.com/images/1234.png") - @citizen = Factory(:citizen, :profile => profile) + profile = FactoryGirl.create(:profile, :image => "http://www.facebook.com/images/1234.png") + @citizen = FactoryGirl.create(:citizen, :profile => profile) end it "should use user specified profile picture" do @@ -15,7 +15,7 @@ context "without profile picture" do before do - @citizen = Factory(:citizen, :email => "foo@example.com") + @citizen = FactoryGirl.create(:citizen, :email => "foo@example.com") end it "should use gravatar as a fallback" do @@ -25,8 +25,8 @@ end describe "#locked?" do - let(:locked_citizen) { Factory(:citizen, locked_at: Time.now.in_time_zone) } - let(:unlocked_citizen) { Factory(:citizen) } + let(:locked_citizen) { FactoryGirl.create(:citizen, locked_at: Time.now.in_time_zone) } + let(:unlocked_citizen) { FactoryGirl.create(:citizen) } it "tells if a Citizen account is locked" do locked_citizen.locked?.should be_true @@ -35,7 +35,7 @@ end describe "#lock!" do - let(:citizen) { Factory(:citizen) } + let(:citizen) { FactoryGirl.create(:citizen) } it "locks a citizen account" do citizen.locked?.should be_false @@ -45,7 +45,7 @@ end describe "#unlock!" do - let(:citizen) { Factory(:citizen, locked_at: Time.now.in_time_zone) } + let(:citizen) { FactoryGirl.create(:citizen, locked_at: Time.now.in_time_zone) } it "locks a citizen account" do citizen.locked?.should be_true @@ -55,8 +55,8 @@ end describe "#active_for_authentication?" do - let(:locked_citizen) { Factory(:citizen, locked_at: Time.now.in_time_zone) } - let(:unlocked_citizen) { Factory(:citizen) } + let(:locked_citizen) { FactoryGirl.create(:citizen, locked_at: Time.now.in_time_zone) } + let(:unlocked_citizen) { FactoryGirl.create(:citizen) } it "tells if a Citizen account can log in" do locked_citizen.active_for_authentication?.should be_false diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index d9a31b0e..0eaa33a2 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -4,7 +4,7 @@ it { should belong_to :author } it { should belong_to :commentable } - let(:comment) { Factory(:comment) } + let(:comment) { FactoryGirl.create(:comment) } describe "Validations" do describe "body" do @@ -39,8 +39,8 @@ end describe "#prepare_for_unpublishing" do - let(:invalid_comment) { Factory.build(:comment, body: "") } - let(:invalid_comment_2) { Factory.build(:comment, body: "a") } + let(:invalid_comment) { FactoryGirl.build(:comment, body: "") } + let(:invalid_comment_2) { FactoryGirl.build(:comment, body: "a") } it "adds two spaces for empty comments" do invalid_comment.prepare_for_unpublishing diff --git a/spec/models/idea_spec.rb b/spec/models/idea_spec.rb index c78ca2df..d4bc3bee 100644 --- a/spec/models/idea_spec.rb +++ b/spec/models/idea_spec.rb @@ -7,8 +7,8 @@ it { should ensure_length_of(:title).is_at_least(5).with_short_message(/on liian lyhyt/) } it { should ensure_length_of(:body).is_at_least(5).with_short_message(/ideasi hieman/) } - let(:idea) { Factory(:idea) } - let(:citizen) { Factory(:citizen) } + let(:idea) { FactoryGirl.create(:idea) } + let(:citizen) { FactoryGirl.create(:citizen) } describe ".per_page" do it "returns number of items per page" do @@ -99,14 +99,14 @@ end it "calculates vote proportion" do - another_citizen = Factory(:citizen) + another_citizen = FactoryGirl.create(:citizen) idea.vote(citizen, "0") idea.vote(another_citizen, "1") idea.vote_proportion.should be_within(0.001).of(1.0/2) end it "calculates vote_proportion_away_mid" do - another_citizen = Factory(:citizen) + another_citizen = FactoryGirl.create(:citizen) idea.vote(citizen, "0") idea.vote(another_citizen, "1") idea.vote_proportion_away_mid.should be_within(0.001).of(0.0) @@ -123,8 +123,8 @@ describe "#vote_counts" do before do - 5.times { Factory(:vote, option: "1", idea: idea) } - 3.times { Factory(:vote, option: "0", idea: idea) } + 5.times { FactoryGirl.create(:vote, option: "1", idea: idea) } + 3.times { FactoryGirl.create(:vote, option: "0", idea: idea) } end it "returns the vote counts" do @@ -156,9 +156,9 @@ describe "Scopes" do before do - 3.times { Factory(:idea, publish_state: "published" ) } - 2.times { Factory(:idea, publish_state: "unpublished" ) } - 1.times { Factory(:idea, publish_state: "in_moderation" ) } + 3.times { FactoryGirl.create(:idea, publish_state: "published" ) } + 2.times { FactoryGirl.create(:idea, publish_state: "unpublished" ) } + 1.times { FactoryGirl.create(:idea, publish_state: "in_moderation" ) } end describe ".published" do diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index ae916687..9d347057 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -4,7 +4,7 @@ it { should belong_to :citizen } describe "#name" do - let(:citizen) { Factory(:citizen) } + let(:citizen) { FactoryGirl.create(:citizen) } it "returns the full name of the citizen" do citizen.name.should == "Erkki Esimerkki" diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb index 27c58a85..a350ea9d 100644 --- a/spec/models/signature_spec.rb +++ b/spec/models/signature_spec.rb @@ -29,7 +29,7 @@ describe "create_with_citizen_and_idea" do before do @citizen = mock_model(Citizen, :first_names => "John", :last_name => "Doe") - @idea = Factory :idea, :title => "helmet compulsory" + @idea = FactoryGirl.create :idea, :title => "helmet compulsory" @signature = Signature.create_with_citizen_and_idea(@citizen, @idea) end diff --git a/spec/models/vote_spec.rb b/spec/models/vote_spec.rb index 1abdc6c0..abd13fe2 100644 --- a/spec/models/vote_spec.rb +++ b/spec/models/vote_spec.rb @@ -1,14 +1,14 @@ require 'spec_helper' describe Vote do - let(:idea) { Factory(:idea) } - let(:citizen) { Factory(:citizen) } + let(:idea) { FactoryGirl.create(:idea) } + let(:citizen) { FactoryGirl.create(:citizen) } describe ".by" do before do 5.times { Vote.create(option: 1, idea: idea) } - Factory(:vote, option: 1, citizen: citizen, idea: idea) - Factory(:vote, option: 0, citizen: citizen, idea: nil) + FactoryGirl.create(:vote, option: 1, citizen: citizen, idea: idea) + FactoryGirl.create(:vote, option: 0, citizen: citizen, idea: nil) end subject { @scope.by(citizen) } @@ -27,8 +27,8 @@ describe ".in_favor" do before do - 5.times { Factory(:vote, option: 1, idea: idea) } - 3.times { Factory(:vote, option: 0, idea: idea) } + 5.times { FactoryGirl.create(:vote, option: 1, idea: idea) } + 3.times { FactoryGirl.create(:vote, option: 0, idea: idea) } end subject { Vote.in_favor } @@ -40,8 +40,8 @@ describe ".against" do before do - 5.times { Factory(:vote, option: 1, idea: idea) } - 3.times { Factory(:vote, option: 0, idea: idea) } + 5.times { FactoryGirl.create(:vote, option: 1, idea: idea) } + 3.times { FactoryGirl.create(:vote, option: 0, idea: idea) } end subject { Vote.against } diff --git a/spec/modules/changelogger_spec.rb b/spec/modules/changelogger_spec.rb index 771e2bed..3f2dc5b1 100644 --- a/spec/modules/changelogger_spec.rb +++ b/spec/modules/changelogger_spec.rb @@ -65,7 +65,7 @@ class ChangeloggableItem < ActiveRecord::Base end it "should log a citizen changer" do - citizen = Factory(:citizen) + citizen = FactoryGirl.create(:citizen) Thread.current[:changer] = citizen lambda { @item.save! @@ -75,7 +75,7 @@ class ChangeloggableItem < ActiveRecord::Base end it "should log an administrator changer" do - administrator = Factory(:administrator) + administrator = FactoryGirl.create(:administrator) Thread.current[:changer] = administrator lambda { @item.save! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 88c7dc62..f576ad5d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ require "rubygems" require "spork" +require 'factory_girl' # --- Instructions --- # Sort the contents of this file into a Spork.prefork and a Spork.each_run @@ -30,6 +31,15 @@ # These instructions should self-destruct in 10 seconds. If they don't, feel # free to delete them. +def min_ideas_for_homepage( multiply=1 ) + # temporary used for pass homepage tests + # We will do different aproach after test_suite repair + ideas_count = Idea.count + if ideas_count < (6*multiply) + (6*multiply - ideas_count).times { FactoryGirl.create :idea } + end +end + Spork.prefork do # Loading more in this block will cause your tests to run faster. However, # if you change any configuration or code from libraries loaded here, you'll