kinda-sorta working?
This commit is contained in:
parent
b359152757
commit
ae18098c6d
@ -2,9 +2,24 @@ module Locomotive
|
|||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class CurrentUser < Base
|
class CurrentUser < Base
|
||||||
|
|
||||||
|
include ::Rails.application.routes.url_helpers
|
||||||
|
|
||||||
def logged_in?
|
def logged_in?
|
||||||
_source.present?
|
_source.present?
|
||||||
end
|
end
|
||||||
|
def name
|
||||||
|
_source.account.name if logged_in?
|
||||||
|
end
|
||||||
|
def email
|
||||||
|
_source.account.email if logged_in?
|
||||||
|
end
|
||||||
|
def logout_path
|
||||||
|
destroy_admin_session_path
|
||||||
|
end
|
||||||
|
def login_path
|
||||||
|
new_admin_session_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,7 @@ module Locomotive
|
|||||||
'url' => request.url,
|
'url' => request.url,
|
||||||
'now' => Time.now.utc,
|
'now' => Time.now.utc,
|
||||||
'today' => Date.today,
|
'today' => Date.today,
|
||||||
'current_user' => Locomotive::Liquid::Drops::CurrentUser.new(current_user)
|
'current_user' => Locomotive::Liquid::Drops::CurrentUser.new(current_admin)
|
||||||
}
|
}
|
||||||
|
|
||||||
assigns.merge!(Locomotive.config.context_assign_extensions)
|
assigns.merge!(Locomotive.config.context_assign_extensions)
|
||||||
|
@ -13,25 +13,51 @@ describe Locomotive::Liquid::Drops::CurrentUser do
|
|||||||
@controller.stubs(:params).returns(:url => '/subpage')
|
@controller.stubs(:params).returns(:url => '/subpage')
|
||||||
@controller.stubs(:request).returns(OpenStruct.new(:url => '/subpage', :fullpath => '/subpage'))
|
@controller.stubs(:request).returns(OpenStruct.new(:url => '/subpage', :fullpath => '/subpage'))
|
||||||
@controller.current_site = @site
|
@controller.current_site = @site
|
||||||
|
|
||||||
|
@admin = FactoryGirl.build(:admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expect_render(template, text)
|
||||||
|
@page.raw_template = template
|
||||||
|
@page.send(:serialize_template)
|
||||||
|
@controller.expects(:render).with(:text => text, :layout => false, :status => :ok).returns(true)
|
||||||
|
@controller.send(:render_locomotive_page)
|
||||||
|
end
|
||||||
|
|
||||||
context '#logged_in?' do
|
context '#logged_in?' do
|
||||||
it 'returns false when no user is logged in' do
|
it 'returns false when no user is logged in' do
|
||||||
@page.raw_template = '{{ current_user.logged_in? }}'
|
expect_render('{{ current_user.logged_in? }}', 'false')
|
||||||
@page.send(:serialize_template)
|
|
||||||
@controller.expects(:render).with(:text => "false", :layout => false, :status => :ok).returns(true)
|
|
||||||
@controller.send(:render_locomotive_page)
|
|
||||||
end
|
end
|
||||||
it 'returns true when there is a user logged in' do
|
it 'returns true when there is a user logged in' do
|
||||||
@page.raw_template = '{{ current_user.logged_in? }}'
|
@controller.expects(:current_admin).twice.returns(true)
|
||||||
@page.send(:serialize_template)
|
expect_render('{{ current_user.logged_in? }}', 'true')
|
||||||
@controller.expects(:render).with(:text => "true", :layout => false, :status => :ok).returns(true)
|
|
||||||
@controller.send(:render_locomotive_page)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#name' do
|
||||||
|
it 'returns nothing when no user is logged in' do
|
||||||
|
expect_render('{{ current_user.name }}', '')
|
||||||
|
end
|
||||||
|
it 'returns the username when the user is logged in' do
|
||||||
|
@controller.expects(:current_admin).twice.returns(@admin)
|
||||||
|
expect_render('{{ current_user.name }}', 'Admin')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
after(:all) do
|
context '#email' do
|
||||||
ENV['APP_TLD'] = nil
|
it 'returns nothing when no user is logged in' do
|
||||||
Locomotive.configure_for_test(true)
|
expect_render('{{ current_user.email }}', '')
|
||||||
|
end
|
||||||
|
it 'returns the username when the user is logged in' do
|
||||||
|
@controller.expects(:current_admin).twice.returns(@admin)
|
||||||
|
expect_render('{{ current_user.email }}', 'admin@locomotiveapp.org')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#logout_path' do
|
||||||
|
it 'returns the logout url' do
|
||||||
|
expect_render('{{ current_user.logout_path }}', '/admin/sign_out')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user