Sha256: f6114b73d906f32813a24d507c819b4d897ffa4319b242310f5a81e086dcf948

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

require 'test_helper'

class TeamTest < ActiveSupport::TestCase
  setup do
    @team = teams(:shopify_developers)
  end

  test ".find_or_create_by_handle first search in the database" do
    assert_equal @team, Team.find_or_create_by_handle('Shopify/developers')
  end

  test ".find_or_create_by_handle fetch the team from github if it's not in the db already" do
    Shipit.github_api.expects(:org_teams).with('shopify', per_page: 100)
    response = stub(rels: {}, data: [new_team])
    Shipit.github_api.expects(:last_response).returns(response)
    assert_difference -> { Team.count }, 1 do
      Team.find_or_create_by_handle('Shopify/new-team')
    end
  end

  test "#refresh_members! fetch all the team members from github" do
    response = stub(rels: {members: members_resource})
    Shipit.github_api.expects(:get).with(@team.api_url).returns(response)
    assert_difference -> { User.count }, 1 do
      @team.refresh_members!
    end
  end

  private

  def members_resource
    stub(get: stub(data: [george], rels: {}))
  end

  def george
    rels = {self: stub(href: 'https://api.github.com/user/george')}
    stub(id: 42, name: 'George Abitbol', login: 'george', email: 'george@cyclim.se', rels: rels)
  end

  def new_team
    stub(
      id: 24,
      name: 'New Team',
      slug: 'new-team',
      url: 'https://example.com',
      description: 'The Best one',
      organization: 'shopify',
    )
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
shipit-engine-0.5.2 test/models/team_test.rb
shipit-engine-0.5.1 test/models/team_test.rb
shipit-engine-0.5.0 test/models/team_test.rb
shipit-engine-0.4.10 test/models/team_test.rb
shipit-engine-0.4.9 test/models/team_test.rb
shipit-engine-0.4.8 test/models/team_test.rb
shipit-engine-0.4.7 test/models/team_test.rb
shipit-engine-0.4.6 test/models/team_test.rb
shipit-engine-0.4.5 test/models/team_test.rb
shipit-engine-0.4.4 test/models/team_test.rb
shipit-engine-0.4.3 test/models/team_test.rb
shipit-engine-0.4.2 test/models/team_test.rb
shipit-engine-0.4.1 test/models/team_test.rb
shipit-engine-0.4.0 test/models/team_test.rb
shipit-engine-0.3.1 test/models/team_test.rb
shipit-engine-0.3.0 test/models/team_test.rb