summaryrefslogtreecommitdiff
path: root/spec/models/event_spec.rb
blob: 188f09978a7bf6c84a7a36d6db7200ff7df0140c (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
# == Schema Information
#
# Table name: events
#
#  id          :integer(4)      not null, primary key
#  target_type :string(255)
#  target_id   :integer(4)
#  title       :string(255)
#  data        :text
#  project_id  :integer(4)
#  created_at  :datetime        not null
#  updated_at  :datetime        not null
#  action      :integer(4)
#  author_id   :integer(4)
#

require 'spec_helper'

describe Event do
  describe "Associations" do
    it { should belong_to(:project) }
  end

  describe "Respond to" do
    it { should respond_to(:author_name) }
    it { should respond_to(:author_email) }
    it { should respond_to(:issue_title) }
    it { should respond_to(:merge_request_title) }
    it { should respond_to(:commits) }
  end

  describe "Creation" do
    before do 
      @event = Factory :event
    end

    it "should create a valid event" do 
      @event.should be_valid
    end
  end

  describe "Push event" do 
    before do 
      project = Factory :project
      @user = project.owner

      data = { 
        before: "0000000000000000000000000000000000000000",
        after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
        ref: "refs/heads/master",
        user_id: @user.id,
        user_name: @user.name,
        repository: {
          name: project.name,
          url: "localhost/rubinius",
          description: "",
          homepage: "localhost/rubinius",
          private: true
        }
      }

      @event = Event.create(
        project: project,
        action: Event::Pushed,
        data: data,
        author_id: @user.id
      )
    end

    it { @event.push?.should be_true }
    it { @event.allowed?.should be_true }
    it { @event.new_branch?.should be_true }
    it { @event.tag?.should be_false }
    it { @event.branch_name.should == "master" }
    it { @event.author.should == @user }
  end
end