Commit 8ee0993fdf783ad12823ff817cd531df0bc363eb

Authored by Dmitriy Zaporozhets
1 parent ef32e01b

Event & Wiki models specs

app/models/wiki.rb
... ... @@ -7,7 +7,6 @@ class Wiki < ActiveRecord::Base
7 7  
8 8 before_update :set_slug
9 9  
10   -
11 10 def to_param
12 11 slug
13 12 end
... ...
spec/factories.rb
... ... @@ -64,9 +64,11 @@ Factory.add(:web_hook, WebHook) do |obj|
64 64 obj.url = Faker::Internet.url
65 65 end
66 66  
67   -Factory.add(:wikis, WebHook) do |obj|
  67 +Factory.add(:wiki, Wiki) do |obj|
68 68 obj.title = Faker::Lorem.sentence
69 69 obj.content = Faker::Lorem.sentence
  70 + obj.user = Factory(:user)
  71 + obj.project = Factory(:project)
70 72 end
71 73  
72 74 Factory.add(:event, Event) do |obj|
... ...
spec/models/event_spec.rb
... ... @@ -20,6 +20,14 @@ describe Event do
20 20 it { should belong_to(:project) }
21 21 end
22 22  
  23 + describe "Respond to" do
  24 + it { should respond_to(:author_name) }
  25 + it { should respond_to(:author_email) }
  26 + it { should respond_to(:issue_title) }
  27 + it { should respond_to(:merge_request_title) }
  28 + it { should respond_to(:commits) }
  29 + end
  30 +
23 31 describe "Creation" do
24 32 before do
25 33 @event = Factory :event
... ... @@ -29,4 +37,40 @@ describe Event do
29 37 @event.should be_valid
30 38 end
31 39 end
  40 +
  41 + describe "Push event" do
  42 + before do
  43 + project = Factory :project
  44 + @user = project.owner
  45 +
  46 + data = {
  47 + :before => "0000000000000000000000000000000000000000",
  48 + :after => "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
  49 + :ref => "refs/heads/master",
  50 + :user_id => @user.id,
  51 + :user_name => @user.name,
  52 + :repository => {
  53 + :name => project.name,
  54 + :url => "localhost/rubinius",
  55 + :description => "",
  56 + :homepage => "localhost/rubinius",
  57 + :private => true
  58 + }
  59 + }
  60 +
  61 + @event = Event.create(
  62 + :project => project,
  63 + :action => Event::Pushed,
  64 + :data => data,
  65 + :author_id => @user.id
  66 + )
  67 + end
  68 +
  69 + it { @event.push?.should be_true }
  70 + it { @event.allowed?.should be_true }
  71 + it { @event.new_branch?.should be_true }
  72 + it { @event.new_tag?.should be_false }
  73 + it { @event.branch_name.should == "master" }
  74 + it { @event.author.should == @user }
  75 + end
32 76 end
... ...
spec/models/wiki_spec.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Wiki do
  4 + describe "Associations" do
  5 + it { should belong_to(:project) }
  6 + it { should belong_to(:user) }
  7 + end
  8 +
  9 + describe "Validation" do
  10 + it { should validate_presence_of(:title) }
  11 + it { should validate_presence_of(:content) }
  12 + it { should validate_presence_of(:user_id) }
  13 + end
  14 +
  15 + it { Factory(:wiki).should be_valid }
  16 +end
  17 +# == Schema Information
  18 +#
  19 +# Table name: snippets
  20 +#
  21 +# id :integer not null, primary key
  22 +# title :string(255)
  23 +# content :text
  24 +# author_id :integer not null
  25 +# project_id :integer not null
  26 +# created_at :datetime
  27 +# updated_at :datetime
  28 +# file_name :string(255)
  29 +# expires_at :datetime
  30 +#
  31 +
... ...