# 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 'making sure the spec runner works' do it 'factory creates a user with a person saved' do user = Factory.create(:user) loaded_user = User.find(user.id) loaded_user.person.owner_id.should == user.id end describe 'fixtures' do it 'loads fixtures' do User.count.should_not == 0 end end describe '#connect_users' do before do @user1 = User.where(:username => 'alice').first @user2 = User.where(:username => 'eve').first @aspect1 = @user1.aspects.first @aspect2 = @user2.aspects.first connect_users(@user1, @aspect1, @user2, @aspect2) end it 'connects the first user to the second' do contact = @user1.contact_for @user2.person contact.should_not be_nil @user1.contacts.reload.include?(contact).should be_true @aspect1.contacts.include?(contact).should be_true contact.aspects.include?(@aspect1).should be_true end it 'connects the second user to the first' do contact = @user2.contact_for @user1.person contact.should_not be_nil @user2.contacts.reload.include?(contact).should be_true @aspect2.contacts.include?(contact).should be_true contact.aspects.include?(@aspect2).should be_true end it 'allows posting after running' do message = @user1.post(:status_message, :text => "Connection!", :to => @aspect1.id) @user2.reload.visible_posts.should include message end end describe '#comment' do it "should send a user's comment on a person's post to that person" do person = Factory.create(:person) person_status = Factory.create(:status_message, :author => person) m = mock() m.stub!(:post) Postzord::Dispatch.should_receive(:new).and_return(m) alice.comment "yo", :post => person_status end end describe I18n do include ActionView::Helpers::TranslationHelper it 'MissingInterpolationError in a non-english locale is not fatal' do I18n.locale = 'it' I18n.backend.should_receive(:lookup).ordered. with(:it, 'bob', nil, :hey => "what", :fallback => true). and_return("%{not_present} failure") I18n.backend.should_receive(:lookup).ordered. with(:en, 'bob', nil, :hey => "what", :fallback => true). and_return("English translation") translation = translate('bob', :hey => "what") translation.should == "English translation" end it 'MissingInterpolationError with no fallback is fatal' do I18n.backend.stub!(:lookup). with(:en, 'bob', nil, :hey => "what", :fallback => true). and_return("English translation %{that_will_fail}") lambda { translate('bob', :hey => "what") }.should raise_error I18n::MissingInterpolationArgument end end end