Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove obsolete testunit tests

  • Loading branch information...
commit e26d12d252e5d3b03b38b4b43a2151b1fbe15c81 1 parent be603da
@Tarrasch Tarrasch authored
Showing with 0 additions and 2,904 deletions.
  1. +0 −9 test/performance/browsing_test.rb
  2. +0 −19 test/unit/cloner_test.rb
  3. +0 −231 test/unit/committership_test.rb
  4. +0 −264 test/unit/event_test.rb
  5. +0 −153 test/unit/favorite_test.rb
  6. +0 −6 test/unit/feed_item_test.rb
  7. +0 −165 test/unit/group_test.rb
  8. +0 −5 test/unit/helpers/accounts_helper_test.rb
  9. +0 −5 test/unit/helpers/admin/users_helper_test.rb
  10. +0 −77 test/unit/membership_test.rb
  11. +0 −86 test/unit/merge_request_status_test.rb
  12. +0 −178 test/unit/merge_request_version_test.rb
  13. +0 −122 test/unit/page_test.rb
  14. +0 −57 test/unit/processors/merge_request_git_backend_processor_test.rb
  15. +0 −36 test/unit/processors/merge_request_processor_test.rb
  16. +0 −72 test/unit/processors/merge_request_version_processor_test.rb
  17. +0 −30 test/unit/processors/message_forwarding_processor_test.rb
  18. +0 −311 test/unit/processors/push_event_processor_test.rb
  19. +0 −38 test/unit/processors/repository_archiving_processor_test.rb
  20. +0 −42 test/unit/processors/repository_creation_processor_test.rb
  21. +0 −37 test/unit/processors/ssh_key_processor_test.rb
  22. +0 −137 test/unit/processors/web_hook_processor_test.rb
  23. +0 −420 test/unit/project_test.rb
  24. +0 −33 test/unit/role_test.rb
  25. +0 −22 test/unit/site_test.rb
  26. +0 −53 test/unit/ssh_key_file_test.rb
  27. +0 −219 test/unit/ssh_key_test.rb
  28. +0 −77 test/unit/status_tag_test.rb
View
9 test/performance/browsing_test.rb
@@ -1,9 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-# Profiling results for each test method are written to tmp/performance.
-class BrowsingTest < ActionDispatch::PerformanceTest
- def test_homepage
- get '/'
- end
-end
View
19 test/unit/cloner_test.rb
@@ -1,19 +0,0 @@
-# encoding: utf-8
-
-require_relative "../test_helper"
-gem("geoip", ">=0")
-require 'geoip'
-
-class ClonerTest < ActiveSupport::TestCase
-
- def setup
- @geoip = GeoIP.new(File.join(Rails.root, "data", "GeoIP.dat"))
- @cloner = Cloner.new
- end
-
- should " has a valid country" do
- localization = @geoip.country(cloners(:argentina).ip)
- assert_equal cloners(:argentina).country_code, localization[3]
- assert_equal cloners(:argentina).country, localization[5]
- end
-end
View
231 test/unit/committership_test.rb
@@ -1,231 +0,0 @@
-# encoding: utf-8
-
-
-require_relative "../test_helper"
-
-class CommittershipTest < ActiveSupport::TestCase
-
- should_validate_presence_of :repository_id, :committer_type, :committer_id
-
- should " have a creator" do
- committership = new_committership
- assert_equal users(:johan), committership.creator
- end
-
- should "have a polymorphic committer" do
- c = new_committership(:committer => users(:johan))
- assert_equal users(:johan), c.committer
-
- c = new_committership(:committer => groups(:team_thunderbird))
- assert_equal groups(:team_thunderbird), c.committer
- end
-
- should "have a members attribute that's the user if the committer is a user" do
- c = new_committership(:committer => users(:johan))
- assert_equal [users(:johan)], c.members
- end
-
- should 'notify all admin committers in the repository when a new committership is added' do
- # raise repositories(:johans).committerships.inspect
- # Find repository#owner. If group: notify each group member, else notify owner
- owner = users(:johan)
- assert_incremented_by(owner.received_messages, :count, 1) do
- c = new_committership(:committer => groups(:team_thunderbird))
- c.save
- end
- end
-
- should 'nullify notifiable_type and notifiable_id when destroyed' do
- owner = users(:johan)
- c = new_committership(:committer => groups(:team_thunderbird))
- c.save
- message = owner.received_messages.last
- assert_equal c, message.notifiable
- c.destroy
- message.reload
- assert_nil message.notifiable_type
- assert_nil message.notifiable_id
- end
-
- should "have a members attribute that's the group members if the committer is a Group" do
- c = new_committership(:committer => groups(:team_thunderbird))
- assert_equal groups(:team_thunderbird).members, c.members
- end
-
- should "have a named scope for only getting groups" do
- Committership.delete_all
- c1 = new_committership(:committer => groups(:team_thunderbird))
- c2 = new_committership(:committer => users(:johan))
- [c1, c2].each(&:save)
- repo = repositories(:johans)
-
- assert_equal [c1], repo.committerships.groups
- assert_equal [c2], repo.committerships.users
- end
-
- context "Event hooks" do
- setup do
- @committership = new_committership
- @project = @committership.repository.project
- end
-
- should "create an 'added committer' event on create" do
- assert_difference("@project.events.count") do
- @committership.save!
- end
- assert_equal Action::ADD_COMMITTER, Event.last.action
- end
-
- should "create a 'removed committer' event on destroy" do
- @committership.save!
- assert_difference("@project.events.count") do
- @committership.destroy
- end
- assert_equal Action::REMOVE_COMMITTER, Event.last.action
- end
- end
-
- def new_committership(opts = {})
- Committership.new({
- :repository => repositories(:johans),
- :committer => groups(:team_thunderbird),
- :creator => users(:johan)
- }.merge(opts))
- end
-
- context 'Committership uniqueness' do
- setup{
- @repository = repositories(:johans)
- @repository.committerships.destroy_all
- @owning_group = groups(:team_thunderbird)
- }
-
- should 'not allow the same user to be added as a committer twice' do
- user = users(:moe)
- @repository.committerships.create!(:committer => user)
- duplicate_committership = @repository.committerships.build(:committer => user)
- assert !duplicate_committership.save, 'User is already committer'
- end
-
- should 'not allow the same group to be added as a committer twice' do
- @repository.committerships.create!(:committer => @owning_group)
- duplicate_committership = @repository.committerships.build(:committer => @owning_group)
- assert !duplicate_committership.save, 'Group is already committer'
- end
-
- should 'not allow adding the team adding a repository as a committer' do
- @repository.change_owner_to! @owning_group
- assert_equal @owning_group, @repository.committerships.first.committer
- new_committership = @repository.committerships.build(:committer => @owning_group)
- assert !new_committership.save
- end
- end
-
- context "permissions" do
- setup do
- @repository = repositories(:johans)
- @cs = @repository.committerships.create!(:committer => users(:mike))
- end
-
- should "construct a permission mask" do
- assert_equal Committership::CAN_REVIEW, @cs.permission_mask_for(:review)
- exp = Committership::CAN_REVIEW | Committership::CAN_COMMIT
- assert_equal exp, @cs.permission_mask_for(:review, :commit)
- exp = Committership::CAN_COMMIT | Committership::CAN_ADMIN
- assert_equal exp, @cs.permission_mask_for(:commit, :admin)
- exp = Committership::CAN_REVIEW | Committership::CAN_ADMIN
- assert_equal exp, @cs.permission_mask_for(:admin, :review)
- exp = Committership::CAN_REVIEW|Committership::CAN_COMMIT|Committership::CAN_ADMIN
- assert_equal exp, @cs.permission_mask_for(:admin, :review, :commit)
- end
-
- should "set a permission mask" do
- @cs.build_permissions(:review, :commit)
- assert_equal Committership::CAN_REVIEW | Committership::CAN_COMMIT, @cs.permissions
- end
-
- should "build permissions from either strings or symbols" do
- @cs.build_permissions("review", "commit")
- assert_equal Committership::CAN_REVIEW | Committership::CAN_COMMIT, @cs.permissions
- end
-
- should "not blow up if it receives no permissions" do
- assert_nothing_raised(NoMethodError) { @cs.build_permissions([nil]) }
- assert_nothing_raised(NoMethodError) { @cs.build_permissions(nil) }
- end
-
- should "know if someone can review" do
- @cs.build_permissions(:review)
- assert @cs.reviewer?
- assert !@cs.committer?
- assert !@cs.admin?
- end
-
- should "know if someone can commit" do
- @cs.build_permissions(:commit)
- assert !@cs.reviewer?
- assert @cs.committer?
- assert !@cs.admin?
- end
-
- should "know if someone can admin" do
- @cs.build_permissions(:admin)
- assert !@cs.reviewer?
- assert !@cs.committer?
- assert @cs.admin?
- end
-
- should "know when someone is a committer and reviewer" do
- @cs.build_permissions(:commit, :review)
- assert @cs.committer?
- assert @cs.reviewer?
- assert !@cs.admin?
- end
-
- should "raise if permitted? gets a bad value" do
- assert_raises(RuntimeError) { @cs.permitted?("lulz") }
- assert_raises(RuntimeError) { @cs.permitted?(42) }
- assert_raises(RuntimeError) { @cs.permitted?(:bob) }
- end
-
- should "find all reviewers" do
- @cs.build_permissions(:review)
- @cs.save!
- assert Committership.reviewers.all.include?(@cs)
- end
-
- should "find all committers" do
- @cs.build_permissions(:commit)
- @cs.save!
- assert Committership.committers.all.include?(@cs)
- end
-
- should "find all admins" do
- @cs.build_permissions(:admin)
- @cs.save!
- assert Committership.admins.all.include?(@cs)
- end
-
- should "create an initial set of permissions for an owner with full perms" do
- assert cs = @repository.committerships.create_for_owner!(Group.first)
- assert cs.admin?
- assert cs.committer?
- assert cs.reviewer?
- end
-
- should "get a list of current permissions" do
- @cs.build_permissions(:review, :commit)
- assert_equal [:commit, :review], @cs.permission_list.sort_by(&:to_s)
- end
- end
-
- should "explode on destroy if there's no repository" do
- # The repository will be gone if we're deleting the
- # user/repository and it cascades down to the committership
- cs = new_committership
- cs.save!
- assert_nothing_raised(NoMethodError) do
- cs.repository.user.destroy
- end
- end
-end
View
264 test/unit/event_test.rb
@@ -1,264 +0,0 @@
-# encoding: utf-8
-
-
-require_relative "../test_helper"
-
-class EventTest < ActiveSupport::TestCase
-
- should_have_many :feed_items, :dependent => :destroy
-
- def setup
- @event = new_event
- @user = users(:johan)
- @repository = repositories(:johans)
- @project = @repository.project
- end
-
- subject { @event }
-
- def new_event(opts={})
- c = Event.new({
- :target => repositories(:johans),
- :body => "blabla"
- }.merge(opts))
- c.user = opts[:user] || users(:johan)
- c.project = opts[:project] || @project
- c
- end
-
- should " belong to a user or have an author email" do
- event = Event.new(:target => repositories(:johans), :body => 'blabla', :project => @project, :action => Action::COMMIT)
- assert event.user.nil?
- assert !event.valid?, 'valid? should be false'
- event.email = 'foo@bar.com'
- assert event.user.nil?
- assert event.valid?
- assert_equal 'foo@bar.com', event.git_actor.email
- end
-
- should "belong to a user who commits with an aliased email" do
- event = Event.new(:target => repositories(:johans), :body => 'blabla',
- :project => @project, :action => Action::COMMIT)
- assert_nil event.user
- event.email = emails(:johans1).address
- assert_equal users(:johan), event.user
- end
-
- should "handles setting the actor from a string" do
- event = Event.new
- event.email = "marius@stones.com"
- assert_equal 'marius', event.actor_display
- event = Event.new
- event.email = 'Marius Mathiesen <marius@stones.com>'
- assert_equal 'Marius Mathiesen', event.actor_display
- end
-
- should "provides an actor_display for User objects too" do
- event = Event.new
- user = User.new(:fullname => 'Johan Sørensen', :email => 'johan@johansorensen.com')
- event.user = user
- assert_equal 'Johan Sørensen', event.actor_display
- end
-
- context 'A push event' do
- setup do
- @event = new_event(:action => Action::PUSH)
- assert @event.save
- end
-
- should 'have a method for attaching commit events' do
- commit = @event.build_commit(
- :email => 'Linus Torvalds <linus@kernel.org>',
- :data => 'ffc0fa98',
- :body => 'Adding README')
- assert commit.save
- assert_equal(@event, commit.target)
- assert @event.has_commits?
- assert @event.events.commits.include?(commit)
- assert_equal('commit', commit.kind)
- end
-
- should "know if it has one or several commits" do
- commit = @event.build_commit(
- :email => 'Linus Torvalds <linus@kernel.org>',
- :data => 'ffc0fa98',
- :body => 'Adding README')
- assert commit.save
- assert_equal(@event, commit.target)
- assert @event.has_commits?
- assert @event.single_commit?
- second_commit = @event.build_commit(
- :email => "Linus Torvalds <linus@kernel.org>",
- :data => "ffc1fa98",
- :body => "Removing README")
- assert second_commit.save
- @event.reload
- assert @event.has_commits?
- assert !@event.single_commit?
- end
-
- should "return false for has_commits? unless it's a push event" do
- commit = @event.build_commit(
- :email => 'Linus Torvalds <linus@kernel.org>',
- :data => 'ffc0fa98',
- :body => 'Adding README')
- assert commit.save
- @event.action = Action::COMMENT
- assert !@event.has_commits?
- end
- end
-
- context "Feeditem creation" do
- should "create feed items for all the watchers of the project and target" do
- users(:moe).favorites.create!(:watchable => @project)
- users(:mike).favorites.create!(:watchable => @repository)
- event = new_event(:action => Action::PUSH)
-
- assert_difference("FeedItem.count", 2) do
- event.save!
- end
- assert_equal event, users(:moe).feed_items.last.event
- assert_equal event, users(:mike).feed_items.last.event
- end
-
- should "not create a feed item for commit events" do
- users(:mike).favorites.create!(:watchable => @project)
- event = new_event(:action => Action::COMMIT)
-
- assert_no_difference("users(:mike).feed_items.count") do
- event.save!
- end
- end
-
- should "not notify users about their own events" do
- @user.favorites.create!(:watchable => @project)
- event = new_event(:action => Action::PUSH)
- assert_equal @user, event.user
- assert_no_difference("@user.feed_items.count") do
- event.save!
- end
- end
- end
-
- context "favorite notification" do
- setup do
- @event = new_event(:action => Action::PUSH)
- @favorite = users(:mike).favorites.new(:watchable => @repository)
- @favorite.notify_by_email = true
- @favorite.save!
- end
-
- should "find the favorites for the watchable with email notification turned on" do
- assert_equal [@favorite], @event.favorites_for_email_notification
- @favorite.update_attributes(:notify_by_email => false)
- assert_equal [], @event.favorites_for_email_notification
- end
-
- should "tell the Favorite instances with email notification to notify" do
- @event.expects(:favorites_for_email_notification).returns([@favorite])
- @favorite.expects(:notify_about_event).with(@event)
- @event.save!
- end
-
- should "not notify favorites if instructed not to" do
- @event.expects(:notify_about_event).never
- @event.disable_notifications { @event.notify_subscribers }
- end
-
- should "not notify favorites for commit events" do
- assert !@event.notifications_disabled?
- @event.action = Action::COMMIT
- assert @event.notifications_disabled?
- end
-
- should "check if notifications are disabled before sending notifications" do
- @event.expects(:notifications_disabled?)
- @event.notify_subscribers
- end
- end
-
- context "Archiving" do
- setup do
- @push_event = new_event(:action => Action::PUSH, :created_at => 32.days.ago)
- @commit_event = @push_event.build_commit(
- :email => "Linus Torvalds <linus@kernel.org",
- :data => "ffc099",
- :body => "Removing README",
- :created_at => 33.days.ago)
- @push_event.save
- @commit_event.save
- end
-
- should "have a class method for accessing events to be archived" do
- result = []
- Event.events_for_archive_in_batches(1.month.ago) do |batch|
- batch.each { |event| result << event}
- end
- assert_equal([@push_event], result)
- end
-
- should "include commits with Repository as target when archiving" do
- repository = repositories(:johans)
- initial_commit_event = new_event(
- :action => Action::PUSH,
- :created_at => 32.days.ago,
- :data => "ffc",
- :target => repository)
- initial_commit_event.save!
- result = []
- Event.events_for_archive_in_batches(1.month.ago) do |batch|
- batch.each {|event| result << event}
- end
- assert result.include?(initial_commit_event)
- end
-
- should "not include newer events" do
- result = []
- Event.events_for_archive_in_batches(34.days.ago) do |batch|
- batch.each {|event| result << event}
- end
- assert !result.include?(@push_event)
- end
-
- should "have a class method for archiving events older than n days" do
- cutoff = 30.days.ago
- Event.expects(:events_for_archive_in_batches).yields([@push_event])
- @push_event.expects(:create_archived_event)
- @push_event.expects(:destroy)
- Event.archive_events_older_than(cutoff)
- end
-
- should "run in a transaction" do
- cutoff = 10.days.ago
- Event.expects(:transaction)
- Event.archive_events_older_than(cutoff)
- end
-
- should "create an archived event with our attributes, except id" do
- result = @push_event.create_archived_event
- result.attributes.reject{|k,v|k.to_sym == :id}.each do |name, value|
- assert_equal(value, @push_event.attributes[name], "#{name} should be #{value}")
- end
- end
-
- should "a push event should archive its commit events" do
- ArchivedEvent.delete_all
- result = @push_event.create_archived_event
- assert_equal 1, result.commits.size
- end
-
- should "destroy commit events when archived" do
- result = @push_event.create_archived_event
- assert_equal(0, @push_event.events.reload.size)
- end
-
- should "delete feed items when archiving events" do
- user = users(:mike)
- feed_item = FeedItem.create!(:event => @push_event, :watcher => user)
- @push_event.destroy
- assert_raises ActiveRecord::RecordNotFound do
- feed_item.reload
- end
- end
- end
-end
View
153 test/unit/favorite_test.rb
@@ -1,153 +0,0 @@
-# encoding: utf-8
-
-require_relative "../test_helper"
-
-class FavoriteTest < ActiveSupport::TestCase
- def create_favorited_repo
- user = FactoryGirl.create(:user)
- project = FactoryGirl.create(:project, :user => user, :owner => user)
- repo = FactoryGirl.create(:repository, :user => user, :project => project, :owner => user)
- [user, project, repo]
- end
-
- context "In general" do
- should_validate_presence_of(:watchable_type, :watchable_id,
- :user_id)
- should_belong_to :user
- should_belong_to :watchable
- should_validate_uniqueness_of :user_id, :scoped_to => [:watchable_id, :watchable_type]
- end
-
- context "Watching a repository" do
- setup do
- @user, @project, @repo = create_favorited_repo
- @user.favorites.destroy_all
- end
-
- should "be linked with user's favorites" do
- favorite = @user.favorites.build(:watchable => @repo)
- assert_equal @repo, favorite.watchable
- assert_equal @user, favorite.user
- favorite.save!
- assert @user.favorites.include?(favorite)
- end
-
- should "give access to the watched object" do
- favorite = @user.favorites.create(:watchable => @repo)
- assert @user.watched_objects.include?(@repo)
- end
-
- should "know if the user watches the repo" do
- assert !@repo.watched_by?(@user)
- favorite = @user.favorites.create(:watchable => @repo)
- @repo.favorites.reload
- assert @repo.watched_by?(@user)
- end
- end
-
- context "Generating events after creation" do
- setup {
- @user, @project, @repo = create_favorited_repo
- }
-
- should "create an event when a favorite is created" do
- favorite = @user.favorites.build(:watchable => @repo)
- assert !favorite.event_exists?
- favorite.create_event
- assert_not_nil(favorite_event = @user.events_as_target.last)
- assert favorite.event_exists?
- end
- end
-
- context "Deleting events before deletion" do
- setup {
- @user, @project, @repo = create_favorited_repo
- @favorite = @user.favorites.create :watchable => @repo
- }
-
- should "call to delete events before #destroy" do
- @favorite.expects(:destroy_event)
- @favorite.destroy
- end
-
- should "delete any events in #destroy_events" do
- event = @favorite.create_event
- @favorite.destroy
- assert_raises(ActiveRecord::RecordNotFound) do
- event.reload
- end
- end
- end
-
- context "Watching merge requests" do
- setup {
- @user = users(:mike)
- }
-
- should "return the target repository's project as project" do
- merge_request = merge_requests(:moes_to_johans)
- favorite = @user.favorites.create(:watchable => merge_request)
- assert_equal(merge_request.target_repository.project,
- favorite.project)
- end
- end
-
- context "Watching projects" do
- setup {
- @user = users(:moe)
- }
-
- should "return the project as project" do
- @project = projects(:johans)
- favorite = @user.favorites.create(:watchable => @project)
- assert_equal @project, favorite.project
- end
- end
-
- context "event notifications" do
- setup do
- @user = users(:moe)
- @favorite = @user.favorites.create!({
- :watchable => merge_requests(:moes_to_johans),
- :notify_by_email => true
- })
- @event = Event.new({
- :target => repositories(:johans),
- :body => "blabla",
- :action => Action::PUSH
- })
- @event.user = users(:johan)
- @event.project = projects(:johans)
- @event.save!
- end
-
- should "ask the EventRendering engine to render the event" do
- EventRendering::Text.expects(:render).with(@event).returns("some rendered event")
- @favorite.notify_about_event(@event)
- end
-
- should "deliver the notification email" do
- Mailer.expects(:deliver_favorite_notification).with(@user,
- regexp_matches(/johan pushed/))
- @favorite.notify_about_event(@event)
- end
- end
-
- context "Email notifications" do
- setup do
- @user = users(:moe)
- @repository = repositories(:johans)
- end
-
- should "not be on for opt-out users" do
- favorite = @repository.watched_by!(@user)
- assert !favorite.notify_by_email?
- end
-
- should "be on for opt-in users" do
- @user.default_favorite_notifications = true
- favorite = @repository.watched_by!(@user)
- assert favorite.notify_by_email?
- end
- end
-end
View
6 test/unit/feed_item_test.rb
@@ -1,6 +0,0 @@
-require_relative "../test_helper"
-
-class FeedItemTest < ActiveSupport::TestCase
- should_belong_to :event
- should_belong_to :watcher
-end
View
165 test/unit/group_test.rb
@@ -1,165 +0,0 @@
-# encoding: utf-8
-
-
-require_relative "../test_helper"
-
-class GroupTest < ActiveSupport::TestCase
-
- context "in general" do
- should "uses the name as to_param" do
- group = build(:group)
- assert_equal group.name, group.to_param
- end
- end
-
- context "members" do
- setup do
- @johan = FactoryGirl.create(:user)
- @mike = FactoryGirl.create(:user)
- @group = groups(:team_thunderbird)
- @group.add_member(@mike, Role.admin)
- end
-
- should "knows if a user is a member" do
- assert !@group.member?(@johan), '@group.member?(@johan) should be false'
- assert @group.member?(@mike), '@group.member?(@mike) should be true'
- end
-
- should "know the role of a member" do
- assert_nil @group.role_of_user(@johan)
- assert_equal roles(:admin), @group.role_of_user(@mike)
- assert !@group.admin?(@johan), '@group.admin?(@johan) should be false'
- assert @group.admin?(@mike), '@group.admin?(@mike) should be true'
-
- assert !@group.committer?(@johan), '@group.committer?(@johan) should be false'
- assert @group.committer?(@mike), '@group.committer?(@mike) should be true'
- end
-
- should "can add a user with a role using add_member" do
- assert !@group.member?(@johan), '@group.member?(@johan) should be false'
- @group.add_member(@johan, Role.member)
- assert @group.reload.member?(@johan), '@group.reload.member?(@johan) should be true'
- end
- end
-
- context "Committerships" do
- setup do
- @group = groups(:team_thunderbird)
- end
-
- should "has a committership with a repository" do
- assert_equal repositories(:moes), committerships(:thunderbird_moes).repository
- assert_equal groups(:team_thunderbird), committerships(:thunderbird_moes).committer
- assert @group.participated_repositories.include?(repositories(:moes))
- end
- end
-
- should "has a collection of project ids, of all projects it's somehow associated with" do
- group = groups(:team_thunderbird)
- assert group.all_related_project_ids.include?(projects(:thunderbird).id)
- assert group.all_related_project_ids.include?(repositories(:johans2).project_id)
- assert group.all_related_project_ids.include?(projects(:moes).id)
- end
-
- context "repositories" do
- should "has many repositories" do
- assert groups(:team_thunderbird).repositories.include?(repositories(:johans2))
- end
-
- should "not have wiki repositories in #repositories" do
- wiki = repositories(:johans_wiki)
- wiki.owner = groups(:team_thunderbird)
- wiki.save!
- assert !groups(:team_thunderbird).repositories.include?(wiki)
- end
- end
-
- should "has to_param_with_prefix" do
- grp = build(:group, :name => 'webkit')
- assert_equal "+#{grp.to_param}", grp.to_param_with_prefix
- end
-
- should "has no breadcrumb parent" do
- assert_equal nil, build(:group).breadcrumb_parent
- end
-
- context 'Deleting groups' do
- setup do
- @group = FactoryGirl.create(:group)
- end
-
- should "be possible if 1 member or less" do
- FactoryGirl.create(:membership, :group => @group)
- assert_equal 1, @group.members.count
- assert @group.deletable?
- FactoryGirl.create(:membership, :group => @group)
- assert !@group.deletable?
- end
-
- should 'not be possible if associated projects exist' do
- assert_equal [], @group.projects
- assert @group.deletable?
- project = FactoryGirl.create(:project, :owner => @group, :user => @group.creator)
- assert_equal [project], @group.projects.reload
- assert !@group.deletable?
- end
- end
-
- context "validations" do
- setup {@existing_group = FactoryGirl.create(:group)}
-
- should " have a unique name" do
- group = Group.new({
- :name => @existing_group.name
- })
- assert !group.valid?, 'valid? should be false'
- assert_not_nil group.errors.on(:name)
- end
-
- should " have a alphanumeric name" do
- group = build(:group, :name => "fu bar")
- assert !group.valid?, 'group.valid? should be false'
- assert_not_nil group.errors.on(:name)
- end
-
- should 'require valid names' do
- ['foo_bar', 'foo.bar', 'foo bar'].each do |name|
- g = Group.new
- g.name = name
- assert !g.save
- assert_not_nil(g.errors.on(:name), "#{name} should not be a valid name")
- end
- end
-
- should 'automatically downcase the group name before validation' do
- g = FactoryGirl.create(:group, :name => 'FooWorkers')
- assert_equal('fooworkers', g.name)
- end
- end
-
- context 'Avatars' do
- setup { @group = FactoryGirl.create(:group) }
-
- should 'have a default avatar' do
- assert_equal '/images/default_group_avatar.png', @group.avatar.url
- end
-
- should 'use the correct path when an avatar is set' do
- @group.avatar_file_name = 'foo.png'
- assert_equal "/system/group_avatars/#{@group.name}/original/foo.png", @group.avatar.url
- end
- end
-
- should "not include duplicates in all_participating_in_projects" do
- group = groups(:team_thunderbird)
- r = projects(:johans).repositories.mainlines.first
- r.owner = group
- r.save!
- projects(:moes).repositories.create!({
- :name => "mainline2",
- :owner => group,
- :user => projects(:johans).user,
- })
- assert_equal [group], Group.all_participating_in_projects(projects(:johans, :moes))
- end
-end
View
5 test/unit/helpers/accounts_helper_test.rb
@@ -1,5 +0,0 @@
-# encoding: utf-8
-require 'test_helper'
-
-class AccountsHelperTest < ActionView::TestCase
-end
View
5 test/unit/helpers/admin/users_helper_test.rb
@@ -1,5 +0,0 @@
-# encoding: utf-8
-require 'test_helper'
-
-class Admin::UsersHelperTest < ActionView::TestCase
-end
View
77 test/unit/membership_test.rb
@@ -1,77 +0,0 @@
-# encoding: utf-8
-
-
-require_relative "../test_helper"
-
-class MembershipTest < ActiveSupport::TestCase
- should "have valid associations" do
- assert_equal groups(:team_thunderbird), memberships(:team_thunderbird_mike).group
- assert_equal roles(:admin), memberships(:team_thunderbird_mike).role
- assert_equal users(:mike), memberships(:team_thunderbird_mike).user
- end
-
- context 'Adding members to a group' do
- setup do
- @group = FactoryGirl.create(:group)
- @user = @group.creator
- @inviter = FactoryGirl.create(:user)
- end
-
- should 'send a message to a newly added member after he is added to the group' do
- @user.received_messages.destroy_all
- membership = Membership.build_invitation(@inviter, :user => @user, :group => @group, :role => Role.member)
- assert membership.save
- assert_not_nil message = @user.received_messages.find(:first, :conditions => {:notifiable_id => membership.id, :notifiable_type => membership.class.name})
- assert_equal(@inviter, message.sender)
- assert_equal(membership, message.notifiable)
- end
-
- should 'nullify messages when deleted' do
- @invitee = FactoryGirl.create(:user)
- @user.received_messages.destroy_all
- membership = Membership.build_invitation(@inviter, :user => @invitee, :group => @group, :role => Role.member)
- membership.save
- message = membership.messages.first
- assert membership.destroy
- assert_nil message.reload.notifiable_type
- assert_nil message.notifiable_id
- end
-
- should 'not send a notification if no inviter is set' do
- membership = Membership.new(:user => @user, :group => @group, :role => roles(:member))
- membership.expects(:send_notification).never
- membership.save
- end
- end
-
- context 'The group creator' do
- setup do
- @group = FactoryGirl.create(:group)
- @creator = @group.creator
- @membership = FactoryGirl.create(:membership, :user => @creator, :group => @group)
- assert_equal @creator, @group.creator
- end
-
- should 'not be demotable' do
- @membership.role = Role.member
- assert !@membership.save
- assert !@membership.valid?
- end
-
- should 'not be deletable' do
- assert !@membership.destroy
- end
- end
-
- context 'A membership' do
- setup {
- @group = FactoryGirl.create(:group)
- @membership = FactoryGirl.create(:membership, :user => @group.creator, :group => @group)
- }
-
- should 'be unique for each user' do
- duplicate_membership = Membership.new(:group => @membership.group, :user => @membership.user, :role => @membership.role)
- assert !duplicate_membership.save
- end
- end
-end
View
86 test/unit/merge_request_status_test.rb
@@ -1,86 +0,0 @@
-# encoding: utf-8
-
-require_relative "../test_helper"
-
-class MergeRequestStatusTest < ActiveSupport::TestCase
-
- should_belong_to :project
- should_validate_presence_of :project, :state, :name
-
- context "State" do
- setup do
- @project = Project.first
- @status = MergeRequestStatus.new({
- :project => @project,
- :name => "foo",
- :state => MergeRequest::STATUS_OPEN
- })
- end
-
- should "be open? when the state is open" do
- @status.state = MergeRequest::STATUS_OPEN
- assert @status.open?
- assert !@status.closed?
- end
-
- should "be closed? when the state is closed" do
- @status.state = MergeRequest::STATUS_CLOSED
- assert !@status.open?
- assert @status.closed?
- end
-
- should "create default statuses for a project" do
- MergeRequestStatus.create_defaults_for_project(@project)
- assert_equal 2, @project.reload.merge_request_statuses.size
-
- assert @project.merge_request_statuses.first.open?
- assert @project.merge_request_statuses.first.default?
-
- assert @project.merge_request_statuses.last.closed?
- assert !@project.merge_request_statuses.last.default?
- end
-
- context "updating affected merge requests" do
- setup do
- @merge_requests = @project.repositories.mainlines.map(&:merge_requests).flatten
- assert_equal 3, @merge_requests.size
- assert @status.save
- @merge_requests.last.update_attribute(:status_tag, @status.name)
- end
-
- should "only change the status of the merge requests with the same status_tag" do
- assert_equal MergeRequest::STATUS_PENDING_ACCEPTANCE_OF_TERMS,
- @merge_requests[0].status
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[1].status
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[2].status
-
- @status.state = MergeRequest::STATUS_CLOSED
- @status.save!
-
- assert_equal MergeRequest::STATUS_PENDING_ACCEPTANCE_OF_TERMS,
- @merge_requests[0].reload.status
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[1].reload.status
- assert_equal MergeRequest::STATUS_CLOSED, @merge_requests[2].reload.status
- end
-
- should "only change the status_tag of the merge requests, if the name is changed" do
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[1].status
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[2].status
- @merge_requests[2].update_attribute(:status_tag, @status.name)
-
- assert_equal "open", @merge_requests[1].status_tag.to_s
- assert_equal "foo", @merge_requests[2].status_tag.to_s
-
- @status.name = "SomethingElse"
- @status.save!
-
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[1].reload.status
- assert_equal MergeRequest::STATUS_OPEN, @merge_requests[2].reload.status
- assert_equal "open", @merge_requests[1].reload.status_tag.to_s
- assert_equal "SomethingElse", @merge_requests[2].reload.status_tag.to_s
-
- end
-
- end
- end
-end
View
178 test/unit/merge_request_version_test.rb
@@ -1,178 +0,0 @@
-# encoding: utf-8
-
-
-require_relative "../test_helper"
-
-class MergeRequestVersionTest < ActiveSupport::TestCase
- context 'In general' do
- setup do
- @merge_request = merge_requests(:moes_to_johans)
- @merge_request.stubs(:calculate_merge_base).returns("ffcca0")
- @first_version = @merge_request.create_new_version
- end
-
- should 'ask the target repository for commits' do
- repo = mock("Tracking git repo")
- repo.expects(:commits_between).with(
- @first_version.merge_base_sha,
- @merge_request.merge_branch_name(@first_version.version)
- ).returns([])
- tracking_repo = mock("Tracking repository")
- tracking_repo.stubs(:id).returns(999)
- tracking_repo.stubs(:git).returns(repo)
- @merge_request.stubs(:tracking_repository).returns(tracking_repo)
- @first_version.stubs(:merge_request).returns(@merge_request)
- result = @first_version.affected_commits
- end
-
- should 'cache affected_commits' do
- expected_cache_key = "#{@first_version.cache_key}/affected_commits"
- Rails.cache.expects(:fetch).with(expected_cache_key).returns([])
- @first_version.affected_commits
- end
-
- should "have a unique cache key between versions" do
- second_version = @merge_request.create_new_version
- assert_not_equal @first_version.cache_key, second_version.cache_key
- end
- end
-
- context 'Diff browsing' do
- setup do
- @merge_request = merge_requests(:moes_to_johans)
- @merge_request.stubs(:calculate_merge_base).returns("ffcca0")
- @version = @merge_request.create_new_version
- @diff_backend = mock
- @version.stubs(:diff_backend).returns(@diff_backend)
- end
-
- should 'handle a range' do
- @diff_backend.expects(:commit_diff).with("ffc","ccf", true)
- result = @version.diffs("ffc".."ccf")
- end
-
- should 'handle a single commit' do
- @diff_backend.expects(:single_commit_diff).with("ffc")
- result = @version.diffs("ffc")
- end
-
- should 'handle all commits' do
- @diff_backend.expects(:commit_diff).with(@version.merge_base_sha, @merge_request.ending_commit)
- result = @version.diffs
- end
- end
-
- context "Sha summaries" do
- setup do
- @merge_request = merge_requests(:moes_to_johans)
- @merge_request.stubs(:calculate_merge_base).returns("ffca0")
- @version = @merge_request.create_new_version
- end
-
- should "be the merge base only if no affected commits" do
- @version.stubs(:affected_commits).returns([])
- assert_equal "ffca0", @version.sha_summary
- end
-
- should "specify the first and last affected commits, in reverse order" do
- affected_commits = [
- stub(
- :id => "82f4a08e2c0867956fdc797692e3d127ba7b8e8c", :id_abbrev => "82f4"),
- stub(
- :id => "1e4e040fa4c164537a90303ae95eae3bd895a95e", :id_abbrev => "1e4e")]
- @version.stubs(:affected_commits).returns(affected_commits)
- assert_equal "1e4e-82f4", @version.sha_summary
- assert_equal "1e4e040fa4c164537a90303ae95eae3bd895a95e-82f4a08e2c0867956fdc797692e3d127ba7b8e8c",
- @version.sha_summary(:long)
- end
- end
-
- context "The diff backend" do
- setup {
- @backend = MergeRequestVersion::DiffBackend.new(nil)
- }
-
- should "have a cache key" do
- assert_equal "merge_request_diff_v1_ff0_cc9", @backend.cache_key("ff0", "cc9")
- assert_equal "merge_request_diff_v1_ff0", @backend.cache_key("ff0")
- end
-
- should "ask the cache for diffs for a range of commits" do
- Rails.cache.expects(:fetch).with("merge_request_diff_v1_ff9_cc9").returns("some_string")
- assert_equal "some_string", @backend.commit_diff("ff9", "cc9")
- end
-
- should "ask the cache for diffs for a single commit" do
- Rails.cache.expects(:fetch).with("merge_request_diff_v1_f00").returns("foo_bar")
- assert_equal "foo_bar", @backend.single_commit_diff("f00")
- end
- end
-
- context 'Commenting' do
- setup do
- @merge_request = merge_requests(:moes_to_johans)
- @merge_request.stubs(:calculate_merge_base).returns("ffcca0")
- @first_version = @merge_request.create_new_version
- @comment = @first_version.comments.create(:path => "README", :lines => "1-1:1-32+33",
- :sha1 => "ffac-aafc", :user => @merge_request.user, :body => "Needs more cowbell",
- :project => @merge_request.target_repository.project)
- end
-
- should 'fetch all comments with the specified path and sha' do
- assert_equal([@comment],
- @first_version.comments_for_path_and_sha(@comment.path, "ffac-aafc"))
- end
-
- should 'fetch all comments with the specified sha' do
- assert_equal([@comment], @first_version.comments_for_sha("ffac-aafc"))
- end
-
- should 'combine version and MR comments into a single array' do
- @mr_comment = @merge_request.comments.create!(
- :body => "Beware high gamma levels",
- :user => users(:moe),
- :project => @merge_request.target_repository.project
- )
- assert_equal([@comment, @mr_comment], @first_version.comments_for_sha("ffac-aafc",
- :include_merge_request_comments => true))
- end
-
-
- should 'fetch all comments when given a Range' do
- assert_equal([@comment], @first_version.comments_for_path_and_sha(@comment.path, ("ffac".."aafc")))
- end
-
- should 'not fetch comments with a different sha or path' do
- assert_equal([], @first_version.comments_for_path_and_sha(@comment.path, "fac-afc"))
- assert_equal([], @first_version.comments_for_path_and_sha("foo/bar.rb", "ffac-aafc"))
- end
- end
-
- context "Deletion of branches" do
- setup {
- @version = merge_request_versions(:first_version_of_johans_to_mikes)
- @merge_request = @version.merge_request
- }
-
- should "send a deletion notification when destroyed" do
- @version.expects(:schedule_branch_deletion)
- @version.destroy
- end
-
- should "build a message for deleting the tracking branch" do
- result = {
- :source_repository_path => @merge_request.source_repository.full_repository_path,
- :tracking_repository_path => @merge_request.tracking_repository.full_repository_path,
- :target_branch_name => @merge_request.merge_branch_name(@version.version),
- :source_repository_id => @merge_request.source_repository.id
- }
- assert_equal result, @version.branch_deletion_message
- end
-
- should "send the deletion message to the message queue" do
- connection = ActiveMessaging::Gateway.connection
- connection.expects(:send)
- @version.schedule_branch_deletion
- end
- end
-end
View
122 test/unit/page_test.rb
@@ -1,122 +0,0 @@
-# encoding: utf-8
-
-require_relative "../test_helper"
-require "fileutils"
-
-class PageTest < ActiveSupport::TestCase
-
- def setup
- @path = "/tmp/gts-test-wiki"
- delete_test_repo
- FileUtils.mkdir(@path)
- Dir.chdir(@path) do
- File.open("HowTo.markdown", "wb"){|f| f.puts "Hello world!" }
- ENV['GIT_COMMITTER_NAME'] = "Johan Sørensen"
- ENV['GIT_COMMITTER_EMAIL'] = "johan@johansorensen.com"
- `git init; git add .; git commit --author='Johan Sorensen <johan@johansorensen.com>' -m "first commit"`
- end
- @repo = Grit::Repo.new(@path)
- end
-
- def teardown
- delete_test_repo
- end
-
- should "finds an existing page" do
- page = Page.find("HowTo", @repo)
- assert !page.new?, 'page.new? should be false'
- assert_equal "HowTo.markdown", page.name
- assert_equal "Hello world!\n", page.content
- end
-
- should "raises an error when there's no user set" do
- p = Page.find("HowTo", @repo)
- assert_raises(Page::UserNotSetError) { p.save }
- end
-
- should "updates the content when calling save" do
- p = Page.find("HowTo", @repo)
- p.user = users(:johan)
- p.content = "bye cruel world!"
- assert_equal "bye cruel world!", p.content
- assert_match(/^[a-z0-9]{40}$/, p.save)
- p2 = Page.find("HowTo", @repo)
- assert_equal "bye cruel world!", p2.content
- end
-
- should "creates a new page" do
- p = Page.find("Hello", @repo)
- assert p.new?, 'p.new? should be true'
- assert_equal "", p.content
- p.user = users(:johan)
- assert_match(/^[a-z0-9]{40}$/, p.save)
- assert !Page.find("Hello", @repo).new?, 'Page.find("Hello", @repo).new? should be false'
- assert !Page.find("HowTo", @repo).new?, 'Page.find("HowTo", @repo).new? should be false'
- end
-
- should "supports nested pages" do
- p = Page.find("Hello/World", @repo)
- assert p.new?, 'p.new? should be true'
- assert_equal "Hello/World.markdown", p.name
- p.content = "foo"
- p.user = users(:johan)
- assert_match(/^[a-z0-9]{40}$/, p.save)
-
- p2 = Page.find("Hello/World", @repo)
- assert !p2.new?, 'p2.new? should be false'
- end
-
- should "has a basename without the extension" do
- p = Page.find("HowTo", @repo)
- assert_equal "HowTo", p.title
-
- assert_equal p.title, p.to_param
- end
-
- should 'alias id to to_param' do
- p = Page.find('HowTo', @repo)
- assert_equal(p.to_param, p.id)
- end
-
- should " have a commit" do
- p = Page.find("HowTo", @repo)
- assert_instance_of Grit::Commit, p.commit
- assert_equal "johan@johansorensen.com", p.commit.committer.email
- assert_equal "first commit", p.commit.message
-
- p2 = Page.find("somethingnew", @repo)
- assert p2.new?, 'p2.new? should be true'
- assert_equal nil, p2.commit
- end
-
- should " have a committed by user" do
- p = Page.find("HowTo", @repo)
- assert_equal users(:johan), p.committed_by_user
- end
-
- should " have the commit history of a page" do
- p = Page.find("HowTo", @repo)
- p.content = "something else"
- p.user = users(:johan); p.save
-
- assert_equal 2, p.history.size
- assert_equal "Updated HowTo", p.history.first.message
- assert_equal "first commit", p.history.last.message
- end
-
- should " validate the name of the page" do
- p = Page.find("kernel#wtf", @repo)
- p.user = users(:johan)
- assert !p.valid?, 'p.valid? should be false'
- assert !p.save, 'p.save should be false'
-
- assert Page.find("Kernel", @repo).valid?, 'Page.find("Kernel", @repo).valid? should be true'
- assert Page.find("KernelWhat", @repo).valid?, 'Page.find("KernelWhat", @repo).valid? should be true'
- assert Page.find("KernelWhatTheFsck", @repo).valid?, 'Page.find("KernelWhatTheFsck", @repo).valid? should be true'
- end
-
- def delete_test_repo
- FileUtils.rm_rf(@path) if File.exist?(@path)
- end
-
-end
View
57 test/unit/processors/merge_request_git_backend_processor_test.rb
@@ -1,57 +0,0 @@
-# encoding: utf-8
-
-
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class MergeRequestGitBackendProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = MergeRequestGitBackendProcessor.new
- @merge_request = merge_requests(:moes_to_johans)
- @repository = @merge_request.target_repository
- end
-
- def teardown
- @processor = nil
- end
-
- context "Deleting the merge request and its tracking branch" do
- setup do
- @source_git_repo = mock
- @source_git = mock
- @source_git_repo.stubs(:git).returns(@source_git)
- @merge_request.source_repository.stubs(:git).returns(@source_git_repo)
- @msg = {
- :action => "delete",
- :target_name => @merge_request.target_repository.url_path,
- :merge_branch_name => @merge_request.merge_branch_name,
- :source_repository_id => @merge_request.source_repository.id,
- :target_repository_id => @merge_request.target_repository.id,
- }
- end
-
- should "push to delete the tracking branch" do
- @processor.stubs(:source_repository).returns(@merge_request.source_repository)
- @source_git.expects(:push).with({:timeout => false},
- @merge_request.target_repository.full_repository_path,
- ":#{@merge_request.merge_branch_name}")
- @processor.on_message(@msg.to_json)
- end
-
- should "handle non-existing target gits" do
- assert_nothing_raised do
- @processor.on_message(@msg.to_json)
- end
- end
- end
-
- context "Parsing the action" do
- should "understand the delete command" do
- msg = {:merge_request_id => @merge_request.to_param, :action => "delete"}
- @processor.expects(:do_delete).once
- @processor.on_message(msg.to_json)
- assert_equal :delete, @processor.action
- end
-
- end
-end
View
36 test/unit/processors/merge_request_processor_test.rb
@@ -1,36 +0,0 @@
-# encoding: utf-8
-
-
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class MergeRequestProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = MergeRequestProcessor.new
- @merge_request = merge_requests(:moes_to_johans_open)
- @target_repo = @merge_request.target_repository
- @merge_request.stubs(:target_repository).returns(@target_repo)
- MergeRequest.expects(:find).with(@merge_request.id).returns(@merge_request)
- @tracking_repo = mock("Tracking repository")
- @tracking_repo.stubs(:real_gitdir).returns("ff0/bbc/234")
- @target_repo.stubs(:create_tracking_repository).returns(@tracking_repo)
- end
-
- should 'send a repo creation message when the target repo does not have a MR repo' do
- message = {'merge_request_id' => @merge_request.id}.to_json
- @target_repo.expects(:has_tracking_repository?).once.returns(false)
- Repository.expects(:clone_git_repository).with(
- @tracking_repo.real_gitdir,
- @merge_request.target_repository.real_gitdir, :skip_hooks => true).once
- @merge_request.expects(:'push_to_tracking_repository!').with(true).once
- @processor.on_message(message)
- end
-
- should 'create a new branch from the merge request' do
- message = {'merge_request_id' => @merge_request.id}.to_json
- @target_repo.expects(:'has_tracking_repository?').once.returns(true)
- @processor.expects(:create_tracking_repository).never
- @merge_request.expects(:'push_to_tracking_repository!').once
- @processor.on_message(message)
- end
-end
View
72 test/unit/processors/merge_request_version_processor_test.rb
@@ -1,72 +0,0 @@
-# encoding: utf-8
-
-
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class MergeRequestVersionProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = MergeRequestVersionProcessor.new
- @version = merge_request_versions(:first_version_of_johans_to_mikes)
- @merge_request = @version.merge_request
- @tracking_repository = @merge_request.tracking_repository
- @source_repository = @merge_request.source_repository
- @message = @version.branch_deletion_message
- end
-
- def teardown
- @processor = nil
- end
-
- context "Deletion of merge request tracking branches" do
- setup {
- @processor.parse(@message.to_json)
- }
-
- should "push an empty tag to the target repository" do
- repo = mock
- repo.expects(:push).with(
- {:timeout => false},
- @tracking_repository.full_repository_path,
- ":#{@merge_request.merge_branch_name(@version.version)}"
- )
- @source_repository.expects(:git).returns(mock(:git => repo))
- @processor.stubs(:source_repository).returns(@source_repository)
- @processor.delete_branch
- end
- end
-
- context "Missing git repository" do
- setup { @processor.parse(@message.to_json) }
-
- should "log an appropriate message when source repository is missing" do
- @processor.expects(:log_error)
- @processor.delete_branch
- end
- end
-
- context "Internals" do
- setup {
- @processor.parse(@message.to_json)
- }
-
- should "extract the correct source repository path" do
- assert_equal(@source_repository.full_repository_path,
- @processor.source_repository_path)
- end
-
- should "extract the correct tracking repository path" do
- assert_equal(@tracking_repository.full_repository_path,
- @processor.tracking_repository_path)
- end
-
- should "extract the branch name" do
- assert_equal(@merge_request.merge_branch_name(@version.version),
- @processor.target_branch_name)
- end
-
- should "find the source repository" do
- assert_equal @source_repository, @processor.source_repository
- end
- end
-end
View
30 test/unit/processors/message_forwarding_processor_test.rb
@@ -1,30 +0,0 @@
-# encoding: utf-8
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class MessageForwardingProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = MessageForwardingProcessor.new
- @sender = users(:moe)
- @recipient = users(:mike)
- @message = messages(:johans_message_to_moe)
- end
-
- def teardown
- @processor = nil
- end
-
- should 'increment the number of deliveries by one when receiving a message' do
- json_hash = {:sender_id => @sender.id, :recipient_id => @recipient.id, :subject => "Hello world", :body => "This is just ridiculous", :message_id => @message.id}
- assert_incremented_by(ActionMailer::Base.deliveries, :size, 1) do
- @processor.on_message(json_hash.to_json)
- end
- end
-
- should 'not deliver email if sender or recipient cannot be found' do
- json_hash = {:sender_id => @sender.id, :recipient_id => @recipient.id + 999, :subject => "Hello world", :body => "This is just ridiculous", :message_id => @message.id}
- assert_incremented_by(ActionMailer::Base.deliveries, :size, 0) do
- @processor.on_message(json_hash.to_json)
- end
- end
-end
View
311 test/unit/processors/push_event_processor_test.rb
@@ -1,311 +0,0 @@
-# encoding: utf-8
-
-
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class PushEventProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = PushEventProcessor.new
- end
-
- should "update the last_pushed_at attribute on initial push" do
- stub_git_show
- stub_git_log_and_user
- repo = repositories(:johans)
- repo.update_attribute(:last_pushed_at, nil)
- @processor.expects(:log_events).returns(true)
- @processor.expects(:trigger_hooks)
- json = {
- :gitdir => repo.hashed_path,
- :username => "johan",
- :message => '0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/heads/master',
- }.to_json
- @processor.on_message(json)
- assert_equal users(:johan), @processor.user
- assert_equal repo, @processor.repository
- assert_not_nil repo.reload.last_pushed_at
- assert repo.last_pushed_at > 5.minutes.ago
- end
-
- should "not update the last_pushed_at when updating a merge request" do
- stub_git_show
- stub_git_log_and_user
- repo = repositories(:johans)
- repo.update_attribute(:last_pushed_at, nil)
- @processor.expects(:log_events).returns(true)
- json = {
- :gitdir => repo.hashed_path,
- :username => "johan",
- :message => '0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/merge-requests/42',
- }.to_json
- @processor.on_message(json)
- assert_nil repo.reload.last_pushed_at, "last_pushed_at was updated"
- end
-
- should "returns the correct type and identifier for a new tag" do
- stub_git_show
- @processor.process_push_from_commit_summary "0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/tags/r1.1"
- assert_equal :create, @processor.action
- assert @processor.tag?
-
- assert_equal 1, @processor.events.size
- assert_equal Action::CREATE_TAG, @processor.events.first.event_type
- assert_equal 'r1.1', @processor.events.first.identifier
-
- @processor.expects(:log_event).once
- @processor.log_events
- end
-
- should 'identify non-standard (review) branches, and exclude these from logging' do
- stub_git_show
- @processor.process_push_from_commit_summary "0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/merge-requests/123"
- assert_equal :create, @processor.action
- assert @processor.review?
- assert_equal 0, @processor.events.size
- @processor.expects(:log_event).never
- @processor.log_events
- end
-
- should "returns the correct type and identifier for a new branch" do
- stub_git_log_and_user
- @processor.process_push_from_commit_summary '0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/heads/foo_branch'
- @processor.repository = Repository.first
- assert_equal :create, @processor.action
- assert @processor.head?
- assert_equal 1, @processor.events.size
- assert_equal Action::CREATE_BRANCH, @processor.events.first.event_type
- assert_equal 'foo_branch', @processor.events.first.identifier
- assert_equal users(:johan), @processor.events.first.user
- @processor.expects(:log_event).times(1)
- @processor.log_events
- end
-
- should "return the correct namespaced identifier for a new branch" do
- stub_git_log_and_user
- @processor.process_push_from_commit_summary '0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/heads/foo/bar_branch'
- assert_equal 'foo/bar_branch', @processor.events.first.identifier
- end
-
- should 'only fetch commits for new branches when the new branch is master' do
- stub_git_log_and_user
- @processor.process_push_from_commit_summary '0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/heads/master'
- @processor.repository = Repository.first
- assert_equal :create, @processor.action
- assert @processor.head?
- assert_equal 4, @processor.events.size
- assert_equal Action::CREATE_BRANCH, @processor.events.first.event_type
- assert_equal 'master', @processor.events.first.identifier
- assert_equal Action::COMMIT, @processor.events[1].event_type
- @processor.expects(:log_event).times(4)
- @processor.log_events
- end
-
- should "returns the correct type and a set of events for a commit" do
- stub_git_log_and_user
- @processor.process_push_from_commit_summary "a9934c1d3a56edfa8f45e5f157869874c8dc2c34 33f746e21ef5122511a5a69f381bfdf017f4d66c refs/heads/foo_branch"
- @processor.repository = Repository.first
- assert_equal :update, @processor.action
- assert @processor.head?
- assert_equal 1, @processor.events.size
- first_event = @processor.events.first
- assert_equal Action::PUSH, first_event.event_type
- assert_equal users(:johan).email, first_event.email
- assert_match(/foo_branch changed/, first_event.message)
- assert_equal(3, first_event.commits.size)
-
- assert_incremented_by(Event, :count, 4) do
- @processor.log_events
- end
- end
-
- should "set the correct user for the commit subevent, if a user exists with that email" do
- emails(:johans1).update_attribute(:address, "john@nowhere.com")
- stub_git_log_and_user
- @processor.process_push_from_commit_summary "a9934c1d3a56edfa8f45e5f157869874c8dc2c34 33f746e21ef5122511a5a69f381bfdf017f4d66c refs/heads/foo_branch"
- @processor.repository = Repository.first
- first_event = @processor.events.first
- assert_equal users(:johan).email, first_event.email
- assert_equal(3, first_event.commits.size)
- assert_nil first_event.commits.first.email
- assert_equal users(:johan), first_event.commits.first.user
- end
-
- should "creates commit events even if the committer is unknown" do
- stub_git_log_and_user
- @processor.repository = Repository.first
- @processor.process_push_from_commit_summary '0000000000000000000000000000000000000000 a9934c1d3a56edfa8f45e5f157869874c8dc2c34 refs/heads/master'
- assert_equal :create, @processor.action
- assert_equal 4, @processor.events.size
- assert_equal users(:johan), @processor.events.first.user
- @processor.events[1..4].each do |e|
- assert_equal 'john@nowhere.com', e.email
- end
- end
-
- should "pick the correct merge request to push to" do
- @merge_request = merge_requests(:moes_to_johans)
- MergeRequest.expects(:find_by_sequence_number!).with(@merge_request.to_param).returns(@merge_request)
- @processor.repository = @merge_request.target_repository
- @processor.expects(:action).returns(:update)
- @processor.expects(:target).returns(:review)
- @processor.stubs(:identifier).returns(@merge_request.to_param)
- @merge_request.expects(:update_from_push!)
- @processor.process_push
- end
-
- should "returns the correct type and identifier for the deletion of a tag" do
- stub_git_show
- @processor.process_push_from_commit_summary "a9934c1d3a56edfa8f45e5f157869874c8dc2c34 0000000000000000000000000000000000000000 refs/tags/r1.1"
- assert_equal :delete, @processor.action
- assert @processor.tag?
- assert_equal 1, @processor.events.size
- assert_equal Action::DELETE_TAG, @processor.events.first.event_type
- assert_equal 'r1.1', @processor.events.first.identifier
- assert_equal 'john@nowhere.com', @processor.events.first.email
- assert_equal 'Deleted tag r1.1', @processor.events.first.message
- @processor.expects(:log_event).once
- @processor.log_events
- end
-
- should "returns the correct type and identifier for the deletion of a branch" do
- stub_git_show
- frozen_now = Time.now
- Time.expects(:now).returns(frozen_now)
- @processor.process_push_from_commit_summary 'a9934c1d3a56edfa8f45e5f157869874c8dc2c34 0000000000000000000000000000000000000000 refs/heads/foo_branch'
- assert_equal :delete, @processor.action
- assert @processor.head?
- assert_equal 1, @processor.events.size
- assert_equal Action::DELETE_BRANCH, @processor.events.first.event_type
- assert_equal 'foo_branch', @processor.events.first.identifier
- assert_equal frozen_now.utc, @processor.events.first.commit_time
- @processor.expects(:log_event).once
- @processor.log_events
- end
-
- should "parse the git output correctly in the real world" do
- grit = Grit::Repo.new(grit_test_repo("dot_git"), :is_bare => true)
- @processor.stubs(:git).returns(grit.git)
- @processor.stubs(:user).returns(users(:johan))
-
- @processor.process_push_from_commit_summary "2d3acf90f35989df8f262dc50beadc4ee3ae1560 ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a refs/heads/master"
- @processor.repository = Repository.first
- assert_equal :update, @processor.action
- assert @processor.head?
- assert_equal 1, @processor.events.size
- first_event = @processor.events.first
- assert_equal Action::PUSH, first_event.event_type
- assert_equal users(:johan).email, first_event.email
- assert_equal(2, first_event.commits.size)
- commit_event = first_event.commits.first
- assert_equal "ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a", commit_event.identifier
- assert_equal "Scott Chacon <schacon@gmail.com>", commit_event.email
- assert_equal Time.at(1208561228), commit_event.commit_time
- exp_msg = "added a pure-ruby git library and converted the cat_file commands to use it"
- assert_equal exp_msg, commit_event.message
- end
-
- def stub_git_log_and_user
- git = mock
- output = [
- '33f746e21ef5122511a5a69f381bfdf017f4d66c',
- 'john@nowhere.com',
- '1233842115',
- 'This is really nice'
- ].join(PushEventProcessor::PUSH_EVENT_GIT_OUTPUT_SEPARATOR_ESCAPED) + "\n"
- git.stubs(:log).returns(output*3)
- @processor.stubs(:git).returns(git)
- @processor.stubs(:user).returns(users(:johan))
- end
-
- def stub_git_show
- git = mock
- output = [
- "a9934c1d3a56edfa8f45e5f157869874c8dc2c34",
- "john@nowhere.com",
- "1233842115",
- "Whoops, deleting the tag"
- ].join(PushEventProcessor::PUSH_EVENT_GIT_OUTPUT_SEPARATOR_ESCAPED)
- git.stubs(:show).returns(output)
- @processor.stubs(:git).returns(git)
- end
-
- context "Generating commit summaries for web hooks" do
- setup {
- @processor = PushEventProcessor.new
- @processor.user = users(:moe)
-
- @push_event = PushEventProcessor::EventForLogging.new
- @commit_event = PushEventProcessor::EventForLogging.new
-
- @commit_event.email = "marius@gitorious.org"
- @commit_event.identifier = "ffac"
- @commit_event.commit_time = 1.day.ago
- @commit_event.event_type = Action::COMMIT
- @commit_event.message = "A single commit"
- @commit_event.commit_details = {
- :sha => "ffcc",
- :author => {
- :name => "John Doe",
- :email => "john@gitorious.org"
- },
- :committed_time => 1.day.ago.xmlschema,
- :message => "One commit"
- }
-
- @push_event.commits = [@commit_event]
-
- commit_summary = "000 fff refs/heads/master"
- @processor.parse_git_spec(commit_summary)
- @repository = repositories(:johans)
- @processor.repository = @repository
- }
-
- should "calculate the correct refs" do
- assert_equal "000", @processor.oldrev
- assert_equal "fff", @processor.newrev
- assert_equal "refs/heads/master", @processor.revname
- end
-
- should "not trigger any hooks if repository has none" do
- @processor.expects(:trigger_hook).never
- @processor.trigger_hooks(Array(@push_event))
- end
-
- should "trigger hook for each event" do
- @repository.hooks.create(:user => @processor.user, :url => "http://postbin.org/")
- @processor.expects(:trigger_hook).once
- @processor.trigger_hooks(Array(@push_event))
- end
-
- should "trigger payload generation" do
- @processor.expects(:generate_hook_payload)
- @processor.trigger_hook(@push_event)
- end
-
- should "generate the correct payload" do
- result = @processor.generate_hook_payload(@push_event)
- assert_not_nil result[:ref]
- assert_not_nil result[:after]
- assert_not_nil result[:before]
- assert_not_nil result[:commits]
- assert_not_nil result[:repository][:url]
- assert_equal "John Doe", result[:commits].first[:author][:name]
- end
- end
-
-
- # describe 'with stubbing towards a live repo' do
- # before(:each) do
- # @repo = Grit::Repo.new("/Users/marius/tmp/clone")
- # @processor.stubs(:git).returns(@repo.git)
- # end
- #
- # it 'should get decent output from git log' do
- # @processor.process_push_from_commit_summary "b808ca5eb8ab40a9fdc3489f9f83f6cf6e726a61 abf17983b01f716f34ee10b3f74f14fe7f3bf4ed refs/heads/master"
- # assert_equal 1, @processor.events.size
- # assert_equal 'marius.mathiesen@gmail.com', @processor.events.first.email
- # assert_equal 'Adding some stuff', @processor.events.first.message
- # end
- # end
-end
View
38 test/unit/processors/repository_archiving_processor_test.rb
@@ -1,38 +0,0 @@
-# encoding: utf-8
-
-require File.dirname(__FILE__) + '/../../test_helper'
-require "fileutils"
-
-class RepositoryArchivingProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = RepositoryArchivingProcessor.new
- repo = repositories(:johans)
- @msg = {
- :full_repository_path => repo.full_repository_path,
- :output_path => "/tmp/output/foo.tar.gz",
- :work_path => "/tmp/work/foo.tar.gz",
- :commit_sha => "abc123",
- :name => "ze_project-reponame",
- :format => "tar.gz",
- }
- end
-
- should "aborts early if the cached file already exists" do
- File.expects(:exist?).with(@msg[:output_path]).returns(true)
- Dir.expects(:chdir).never
- @processor.on_message(@msg.to_json)
- end
-
- should "generates an archived tarball in the work dir and moves it to the cache path" do
- File.expects(:exist?).with(@msg[:output_path]).returns(false)
- Dir.expects(:chdir).yields(Dir.new("/tmp"))
- @processor.expects(:run).with("git archive --format=tar " +
- "--prefix=ze_project-reponame/ abc123 | gzip > #{@msg[:work_path]}").returns(nil)
-
- @processor.expects(:run_successful?).returns(true)
- FileUtils.expects(:mv).with(@msg[:work_path], @msg[:output_path])
-
- @processor.on_message(@msg.to_json)
- end
-end
View
42 test/unit/processors/repository_creation_processor_test.rb
@@ -1,42 +0,0 @@
-# encoding: utf-8
-
-
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class RepositoryCreationProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = RepositoryCreationProcessor.new
- @repository = repositories(:johans)
-
- @clone = mock
- @clone.stubs(:id).returns(99)
- @clone.stubs(:ready).returns(true)
- @clone.expects(:ready=).once.returns(true)
- @clone.expects(:save!).once
- Repository.stubs(:find_by_id).returns(@clone)
- end
-
- should "supplies two repos when cloning an existing repository" do
- Repository.expects(:clone_git_repository).with('foo', 'bar')
- options = {
- :target_class => 'Repository',
- :target_id => @clone.id,
- :command => 'clone_git_repository',
- :arguments => ['foo', 'bar']}
- message = options.to_json
- @processor.on_message(message)
- end
-
- should "supplies one repo when creating a new repo" do
- Repository.expects(:create_git_repository).with('foo')
- options = {
- :target_class => 'Repository',
- :target_id => @clone.id,
- :command => 'create_git_repository',
- :arguments => ['foo']}
- message = options.to_json
- @processor.on_message(message)
- end
-
-end
View
37 test/unit/processors/ssh_key_processor_test.rb
@@ -1,37 +0,0 @@
-# encoding: utf-8
-
-
-require File.dirname(__FILE__) + '/../../test_helper'
-
-class SshKeyProcessorTest < ActiveSupport::TestCase
-
- def setup
- SshKey.any_instance.stubs(:valid_key_using_ssh_keygen?).returns(true)
- @processor = SshKeyProcessor.new
- @key = FactoryGirl.create(:ssh_key, :ready => false)
- end
-
- should "add to authorized keys" do
- assert !@key.ready?
- SshKey.expects(:add_to_authorized_keys).with('fofofo')
- options = {
- :target_class => 'SshKey',
- :command => 'add_to_authorized_keys',
- :arguments => ['fofofo'],
- :target_id => @key.id}
- json = options.to_json
- @processor.on_message(json)
- assert @key.reload.ready?
- end
-
- should "remove from authorized keys" do
- SshKey.expects(:delete_from_authorized_keys).with('fofofo')
- options = {
- :target_class => 'SshKey',
- :command => 'delete_from_authorized_keys',
- :arguments => ['fofofo']
- }
- json = options.to_json
- @processor.on_message(json)
- end
-end
View
137 test/unit/processors/web_hook_processor_test.rb
@@ -1,137 +0,0 @@
-# encoding: utf-8
-require "test_helper"
-class WebHookProcessorTest < ActiveSupport::TestCase
-
- def setup
- @processor = WebHookProcessor.new
- @repository = repositories(:johans)
- @processor.repository = @repository
- @user = users(:mike)
- push_event = PushEventProcessor::EventForLogging.new
- commit = PushEventProcessor::EventForLogging.new
- commit.email = "marius@gitorious.org"
- commit.identifier = "ffc009"
- commit.event_type = Action::COMMIT
- commit.message = "Fixing a bug"
- commit.commit_details = {}
- push_event.commits = [commit]
- @payload = push_event.generate_hook_payload("000", "fff", "refs/heads/master", @user, @repository).with_indifferent_access
- end
-
- def add_hook_url(repository, url)
- repository.hooks.create!(:user => users(:johan), :url => url)
- end
-
- context "Extracting the message" do
- setup do
- assert_not_nil @repository
- @processor.expects(:notify_web_hooks).with(@payload)
- @processor.on_message({
- :user => @user.login,
- :repository_id => @repository.id,
- :payload => @payload}.to_json)
- end
-
- should "extract the repository from the message" do
- assert_equal @repository, @processor.repository
- end
-
- should "extract the user from the message" do
- assert_equal @user, @processor.user
- end
- end
-
- def successful_response
- result = Net::HTTPSuccess.new("HTTP/1.1","200","OK")
- result.stubs(:body).returns("")
- result
- end
-
- def last_hook_response(repository)
- repository.hooks.reload.first.last_response
- end
-
- context "Notifying web hooks" do
-
- should "post the payload once for each hook" do
- add_hook_url(@repository, "http://foo.com/")
- add_hook_url(@repository, "http://bar.com/")
- @processor.expects(:post_payload).twice.returns(successful_response)
- @processor.notify_web_hooks(@payload)
- end
-
- should "do a HTTP POST to the hook url" do
- @url = "http://foo.bar/"
- hook = Hook.new(:url => @url)
- uri = URI.parse(@url)
- Net::HTTP.expects(:post_form).with(uri, {"payload" => @payload.to_json})
- @processor.post_payload(hook, @payload)
- end
-
- should "update the hook with the response string" do
- @url = "http://example.com/hook"
- add_hook_url(@repository, @url)
- @processor.expects(:post_payload).returns(successful_response)
- @processor.notify_web_hooks(@payload)
- assert_equal "200 OK", last_hook_response(@repository)
- end
- end
-
- context "Error handling" do
- setup {
- add_hook_url(@repository, "http://access-denied.com/")
- }
-
- should "handle timeouts" do
- @processor.expects(:post_payload).raises(Timeout::Error, "Connection timed out")
- @processor.notify_web_hooks(@payload)
- assert_equal "Connection timed out", last_hook_response(@repository)
- end
-
- should "handle connection refused" do
- @processor.expects(:post_payload).raises(Errno::ECONNREFUSED, "Connection refused")
- @processor.notify_web_hooks(@payload)
- assert_equal "Connection refused", last_hook_response(@repository)
- end
-
- should "handle socket errors" do
- @processor.expects(:post_payload).raises(SocketError)
- @processor.notify_web_hooks(@payload)
- assert_equal "Socket error", last_hook_response(@repository)
- end
-
- should "log an error for an unknown repository" do
- assert_nothing_raised {
- @processor.expects(:log_error)
- @processor.stubs(:notify_web_hooks)
- @processor.on_message({:user => @user.login, :repository_id => "invalid repository name"}.to_json)
- }
- end
-
- should "log an error for an unknown user" do
- assert_nothing_raised {
- @processor.expects(:log_error)
- @processor.stubs(:notify_web_hooks)
- @processor.on_message({:user => "invalid login", :repository_id => @repository.id}.to_json)
- }
- end
- end
-
- context "HTTP responses" do
- should "consider any response in the 20x range successful" do
- response = Net::HTTPSuccess.new("HTTP/1.1","200","OK")
- assert @processor.successful_response?(response)
- end
-
- should "consider some redirects successful" do
- response = Net::HTTPFound.new("HTTP/1.1","302","Found")
- assert @processor.successful_response?(response)
- end
-
- should "consider all responses in the 40x range unsuccessful" do
- response = Net::HTTPNotFound.new("HTTP/1.1","404","Not found")
- assert !@processor.successful_response?(response)
- end
- end
-
-end
View
420 test/unit/project_test.rb
@@ -1,420 +0,0 @@
-# encoding: utf-8
-
-
-require_relative "../test_helper"
-
-class ProjectTest < ActiveSupport::TestCase
-
-
- def create_project(options={})
- Project.new({
- :title => "foo project",
- :slug => "foo",
- :description => "my little project",
- :user => users(:johan),
- :owner => users(:johan)
- }.merge(options))
- end
-
- should_belong_to :containing_site
- should_have_many :merge_request_statuses
-
- should " have a title to be valid" do
- project = create_project(:title => nil)
- assert !project.valid?, 'valid? should be false'
- project.title = "foo"
- assert project.valid?
- end
-
- should " have a slug to be valid" do
- project = create_project(:slug => nil)
- assert !project.valid?, 'valid? should be false'
- end
-
- should " have a unique slug to be valid" do
- p1 = create_project
- p1.save!
- p2 = create_project(:slug => "FOO")
- assert !p2.valid?, 'valid? should be false'
- assert_not_nil p2.errors.on(:slug)
- end
-
- should " have an alphanumeric slug" do
- project = create_project(:slug => "asd asd")
- project.valid?
- assert !project.valid?, 'valid? should be false'
- end
-
- should " downcase the slug before validation" do
- project = create_project(:slug => "FOO")
- project.valid?
- assert_equal "foo", project.slug
- end
-
- should "cannot have a reserved name as slug" do
- project = create_project(:slug => Gitorious::Reservations.project_names.first)
- project.valid?
- assert_not_nil project.errors.on(:slug)
-
- project = create_project(:slug => "dashboard")
- project.valid?
- assert_not_nil project.errors.on(:slug)
- end
-
- should "creates the wiki repository on create" do
- project = create_project(:slug => "my-new-project")
- project.save!
- assert_instance_of Repository, project.wiki_repository
- assert_equal "my-new-project#{Repository::WIKI_NAME_SUFFIX}", project.wiki_repository.name
- assert_equal Repository::KIND_WIKI, project.wiki_repository.kind
- assert !project.repositories.include?(project.wiki_repository)
- assert_equal project.owner, project.wiki_repository.owner
- end
-
- should "finds a project by slug or raises" do
- assert_equal projects(:johans), Project.find_by_slug!(projects(:johans).slug)
- assert_raises(ActiveRecord::RecordNotFound) do
- Project.find_by_slug!("asdasdasd")
- end
- end
-
- should "has the slug as its params" do
- assert_equal projects(:johans).slug, projects(:johans).to_param
- end
-
- should "knows if a user is a admin on a project" do
- project = projects(:johans)
- assert project.admin?(users(:johan))
- project.owner = groups(:team_thunderbird)
- assert !project.admin?(users(:johan))
- project.owner.add_member(users(:johan), Role.admin)
- assert project.admin?(users(:johan))
-
- assert !project.admin?(users(:moe))
- project.owner.add_member(users(:moe), Role.member)
- assert !project.admin?(users(:moe))
- # be able to deal with AuthenticatedSystem's quirky design:
- assert !project.admin?(:false)
- assert !project.admin?(false)
- assert !project.admin?(nil)
- end
-
- should "knows if a user is a member on a project" do
- project = projects(:johans)
- assert project.member?(users(:johan))
- project.owner = groups(:team_thunderbird)
- assert !project.member?(users(:johan))
- project.owner.add_member(users(:johan), Role.member)
- assert project.member?(users(:johan))
-
- assert !project.member?(users(:moe))
- project.owner.add_member(users(:moe), Role.member)
- assert !project.admin?(users(:moe))
- # be able to deal with AuthenticatedSystem's quirky design:
- assert !project.member?(:false)
- assert !project.member?(false)
- assert !project.member?(nil)
- end
-
- should "knows if a user can delete the project" do
- project = projects(:johans)
- assert !project.can_be_deleted_by?(users(:moe))
- assert !project.can_be_deleted_by?(users(:johan)) # it has clones..
- project.repositories.clones.each(&:destroy)
- assert project.reload.can_be_deleted_by?(users(:johan)) # the clones are clone
- end
-
- should " strip html tags" do
- project = create_project(:description => "<h1>Project A</h1>\n<b>Project A</b> is a....")
- assert_equal "Project A\nProject A is a....", project.stripped_description
- end
-
- should " have a breadcrumb_parent method which returns nil" do
- project = create_project
- assert project.breadcrumb_parent.nil?
- end
-
- # should "strip html tags, except highlights" do
- # project = create_project(:description => %Q{<h1>Project A</h1>\n<strong class="highlight">Project A</strong> is a....})
- # assert_equal %Q(Project A\n<strong class="highlight">Project A</strong> is a....), # project.stripped_description
- # end
-
- should "have valid urls ( prepending http:// if needed )" do
- project = projects(:johans)
- [ :home_url, :mailinglist_url, :bugtracker_url ].each do |attr|
- assert project.valid?
- project.send("#{attr}=", 'http://blah.com')
- assert project.valid?
- project.send("#{attr}=", 'ftp://blah.com')
- assert !project.valid?, 'valid? should be false'
- project.send("#{attr}=", 'blah.com')
- assert project.valid?
- assert_equal 'http://blah.com', project.send(attr)
- end
- end
-
- should "remove leading and trailing whitespace from the URL" do
- p = projects(:johans)
- assert_equal("http://foo.com/", p.clean_url(" http://foo.com/ "))
- end
-
- should " not prepend http:// to empty urls" do
- project = projects(:johans)
- [ :home_url, :mailinglist_url, :bugtracker_url ].each do |attr|
- project.send("#{attr}=", '')
- assert project.send(attr).blank?
- project.send("#{attr}=", nil)
- assert project.send(attr).blank?
- end
- end
-
- should " find or create an associated wiki repo" do
- project = projects(:johans)
- repo = repositories(:johans)
- repo.kind = Repository::KIND_WIKI
- project.wiki_repository = repo
- project.save!
- assert_equal repo, project.reload.wiki_repository
- end
-
- should " have a wiki repository" do
- project = projects(:johans)
- assert_equal repositories(:johans_wiki), project.wiki_repository
- assert !project.repositories.include?(repositories(:johans_wiki))