File: thread_spec.rb

package info (click to toggle)
atig 0.6.1-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 868 kB
  • sloc: ruby: 5,315; makefile: 11; sh: 3
file content (89 lines) | stat: -rw-r--r-- 2,688 bytes parent folder | download | duplicates (4)
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
# -*- mode:ruby; coding:utf-8 -*-

require 'atig/command/thread'

describe Atig::Command::Thread do
  include CommandHelper
  before do
    u = double 'user'
    @entries = [
                entry(u, status(''),'entry-0'),
                entry(u, status('','in_reply_to_status_id'=>2),'entry-1'),
                entry(u, status('','in_reply_to_status_id'=>3),'entry-2'),
                entry(u, status(''),'entry-3'),
                entry(u, status('','in_reply_to_status_id'=>5),'entry-4')
               ]
    @command = init Atig::Command::Thread
    @messages = []
    allow(@channel).to receive(:message){|entry,_|
      @messages.unshift entry
    }
    allow(@statuses).to receive(:find_by_status_id).with(anything){|id|
      @entries[id.to_i]
    }
  end

  it "should provide thread command" do
    expect(@gateway.names).to eq(%w( thread ))
  end

  it "should show the tweet" do
    expect(@statuses).to receive(:find_by_tid).with('a').and_return(@entries[0])

    call "#twitter","thread",%w(a)

    expect(@messages).to eq([ @entries[0] ])
  end

  it "should chain the tweets" do
    expect(@statuses).to receive(:find_by_tid).with('a').and_return(@entries[1])

    call "#twitter","thread",%w(a)

    expect(@messages).to eq(@entries[1..3])
  end

  it "should chain the tweets by screen name" do
    expect(@statuses).to receive(:find_by_tid).with('mzp').and_return(nil)
    expect(@statuses).to receive(:find_by_sid).with('mzp').and_return(nil)
    expect(@statuses).to receive(:find_by_screen_name).with('mzp',:limit=>1).and_return([ @entries[1] ])

    call "#twitter","thread",%w(mzp)

    expect(@messages).to eq(@entries[1..3])
  end

  it "should chain the tweets by sid" do
    expect(@statuses).to receive(:find_by_tid).with('mzp:a').and_return(nil)
    expect(@statuses).to receive(:find_by_sid).with('mzp:a').and_return(@entries[1])

    call "#twitter","thread",%w(mzp:a)

    expect(@messages).to eq(@entries[1..3])
  end



  it "should chain the tweets with limit" do
    expect(@statuses).to receive(:find_by_tid).with('a').and_return(@entries[1])

    call "#twitter","thread",%w(a 2)

    expect(@messages).to eq(@entries[1..2])
  end

  it "should get new tweets" do
    expect(@statuses).to receive(:find_by_tid).with('a').and_return(@entries[4])
    user   = user 1, 'mzp'
    status = status '','user'=>user
    entry  = entry user,status,'new-entry'
    expect(@statuses).to receive(:add).with(status: status, user: user, source: :thread){
      @entries << entry
    }
    expect(@api).to receive(:get).with('statuses/show/5').and_return(status)

    call "#twitter","thread",%w(a)

    expect(@messages).to eq([@entries[4], entry])
  end
end