projects_controller_spec.rb 2.32 KB
Newer Older
1 2 3 4
require('spec_helper')

describe ProjectsController do
  let(:project) { create(:project) }
Ciro Santilli's avatar
Ciro Santilli committed
5
  let(:public_project) { create(:project, :public) }
6 7
  let(:user)    { create(:user) }
  let(:jpg)     { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') }
Marin Jankovski's avatar
Marin Jankovski committed
8
  let(:txt)     { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') }
9

10 11 12 13 14 15 16 17 18
  describe "GET show" do

    context "when requested by `go get`" do
      render_views

      it "renders the go-import meta tag" do
        get :show, "go-get" => "1", namespace_id: "bogus_namespace", id: "bogus_project"

        expect(response.body).to include("name='go-import'")
19

20 21 22 23
        content = "localhost/bogus_namespace/bogus_project git http://localhost/bogus_namespace/bogus_project.git"
        expect(response.body).to include("content='#{content}'")
      end
    end
24 25 26

    context "when requested with case sensitive namespace and project path" do
      it "redirects to the normalized path for case mismatch" do
Francesco Levorato's avatar
Francesco Levorato committed
27
        get :show, namespace_id: public_project.namespace.path, id: public_project.path.upcase
28

Francesco Levorato's avatar
Francesco Levorato committed
29
        expect(response).to redirect_to("/#{public_project.path_with_namespace}")
30 31 32 33 34 35 36 37
      end

      it "loads the page if normalized path matches request path" do
        get :show, namespace_id: public_project.namespace.path, id: public_project.path

        expect(response.status).to eq(200)
      end
    end
38
  end
39

Ciro Santilli's avatar
Ciro Santilli committed
40
  describe "POST #toggle_star" do
41
    it "toggles star if user is signed in" do
Ciro Santilli's avatar
Ciro Santilli committed
42
      sign_in(user)
43
      expect(user.starred?(public_project)).to be_falsey
44 45
      post(:toggle_star,
           namespace_id: public_project.namespace.to_param,
Vinnie Okada's avatar
Vinnie Okada committed
46
           id: public_project.to_param)
47
      expect(user.starred?(public_project)).to be_truthy
48 49
      post(:toggle_star,
           namespace_id: public_project.namespace.to_param,
Vinnie Okada's avatar
Vinnie Okada committed
50
           id: public_project.to_param)
51
      expect(user.starred?(public_project)).to be_falsey
Ciro Santilli's avatar
Ciro Santilli committed
52 53 54
    end

    it "does nothing if user is not signed in" do
55 56
      post(:toggle_star,
           namespace_id: project.namespace.to_param,
Vinnie Okada's avatar
Vinnie Okada committed
57
           id: public_project.to_param)
58
      expect(user.starred?(public_project)).to be_falsey
59 60
      post(:toggle_star,
           namespace_id: project.namespace.to_param,
Vinnie Okada's avatar
Vinnie Okada committed
61
           id: public_project.to_param)
62
      expect(user.starred?(public_project)).to be_falsey
Ciro Santilli's avatar
Ciro Santilli committed
63 64
    end
  end
65
end