Welcome to mirror list, hosted at ThFree Co, Russian Federation.

notifications_helper_spec.rb « helpers « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e4d599a2ea5d912f4f91b799af85e4ea3687827 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'spec_helper'


describe NotificationsHelper do
  include ApplicationHelper
  before do
    @user = Factory(:user)
    @person = Factory(:person)
    @post = Factory(:status_message, :author => @user.person)
    @person2 = Factory(:person)
    @notification = Notification.notify(@user, Factory(:like, :author => @person, :post => @post), @person)
    @notification =  Notification.notify(@user, Factory(:like, :author => @person2, :post => @post), @person2)

  end
  describe '#notification_people_link' do
    context 'formatting' do
      include ActionView::Helpers::SanitizeHelper
      let(:output){ strip_tags(notification_people_link(@note)) }

      before do
        @max = Factory(:person)
        @max.profile.first_name = 'max'
        @max.profile.last_name = 'salzberg'
        @sarah = Factory(:person)
        @sarah.profile.first_name = 'sarah'
        @sarah.profile.last_name = 'mei'


        @daniel = Factory(:person)
        @daniel.profile.first_name = 'daniel'
        @daniel.profile.last_name = 'grippi'

        @ilya = Factory(:person)
        @ilya.profile.first_name = 'ilya'
        @ilya.profile.last_name = 'zhit'
        @note = mock()
      end

      it 'with two, does not comma seperate two actors' do
        @note.stub!(:actors).and_return([@max, @sarah])
        output.scan(/,/).should be_empty
        output.scan(/and/).count.should be 1
      end

      it 'with three, comma seperates the first two, and and the last actor' do
        @note.stub!(:actors).and_return([@max, @sarah, @daniel])
        output.scan(/,/).count.should be 2
        output.scan(/and/).count.should be 1
      end

      it 'with more than three, lists the first three, then the others tag' do
        @note.stub!(:actors).and_return([@max, @sarah, @daniel, @ilya])
        output.scan(/,/).count.should be 3
        output.scan(/and/).count.should be 2
      end
    end
    describe 'for a like' do
      it 'displays #{list of actors}' do
        output = notification_people_link(@notification)
        output.should include @person2.name
        output.should include @person.name
      end
    end
  end


  describe '#object_link' do
    describe 'for a like' do
      it 'should include a link to the post' do
        output = object_link(@notification, notification_people_link(@notification))
        output.should include post_path(@post)
      end

      it 'includes the boilerplate translation' do
        output = object_link(@notification,  notification_people_link(@notification))
        output.should include t("#{@notification.popup_translation_key}.one",
                                :actors => notification_people_link(@notification),
                                :post_link => "<a href=\"#{post_path(@post)}\" class=\"hard_object_link\" data-ref=\"#{@post.id}\">#{t('notifications.post')}</a>")
      end

      context 'when post is deleted' do
        it 'works' do
          @post.destroy
          expect{ object_link(@notification, notification_people_link(@notification))}.should_not raise_error
        end

        it 'displays that the post was deleted' do
          @post.destroy
          object_link(@notification,  notification_people_link(@notification)).should == t('notifications.liked_post_deleted.one', :actors => notification_people_link(@notification))
        end
      end
    end
  end
end