write specs + refactor the current_user liquid drop
did
committed Feb 06, 2015
commit e7d24748aca184eafe2e7f249d9641c44c6dafb8
Showing 2
changed files with
64 additions
and 17 deletions
locomotive/steam/liquid/drops/current_user.rb b/lib/locomotive/steam/liquid/drops/current_user.rb
+19
-17
| @@ | @@ -1,21 +1,23 @@ |
| - | # module Locomotive |
| - | # module Liquid |
| - | # module Drops |
| - | # class CurrentUser < Base |
| + | module Locomotive |
| + | module Steam |
| + | module Liquid |
| + | module Drops |
| + | class CurrentUser < Base |
| - | # def logged_in? |
| - | # @_source.present? |
| - | # end |
| + | def logged_in? |
| + | @_source.present? |
| + | end |
| - | # def name |
| - | # @_source.name if logged_in? |
| - | # end |
| + | def name |
| + | @_source.name if logged_in? |
| + | end |
| - | # def email |
| - | # @_source.email if logged_in? |
| - | # end |
| + | def email |
| + | @_source.email if logged_in? |
| + | end |
| - | # end |
| - | # end |
| - | # end |
| - | # end |
| + | end |
| + | end |
| + | end |
| + | end |
| + | end |
spec/unit/liquid/drops/current_user_spec.rb
+45
-0
| @@ | @@ -0,0 +1,45 @@ |
| + | require 'spec_helper' |
| + | |
| + | describe Locomotive::Steam::Liquid::Drops::CurrentUser do |
| + | |
| + | let(:drop) { Locomotive::Steam::Liquid::Drops::CurrentUser.new(user) } |
| + | |
| + | subject { drop } |
| + | |
| + | context 'not logged in' do |
| + | |
| + | let(:user) { nil } |
| + | |
| + | describe '#logged_in?' do |
| + | it { expect(subject.logged_in?).to eq false } |
| + | end |
| + | |
| + | describe '#name' do |
| + | it { expect(subject.name).to eq nil } |
| + | end |
| + | |
| + | describe '#email' do |
| + | it { expect(subject.email).to eq nil } |
| + | end |
| + | |
| + | end |
| + | |
| + | context 'logged in' do |
| + | |
| + | let(:user) { instance_double('User', name: 'John', email: 'john@doe.net') } |
| + | |
| + | describe '#logged_in?' do |
| + | it { expect(subject.logged_in?).to eq true } |
| + | end |
| + | |
| + | describe '#name' do |
| + | it { expect(subject.name).to eq 'John' } |
| + | end |
| + | |
| + | describe '#email' do |
| + | it { expect(subject.email).to eq 'john@doe.net' } |
| + | end |
| + | |
| + | end |
| + | |
| + | end |