admin_users_spec.rb 3.72 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2 3 4 5 6
require 'spec_helper'

describe "Admin::Users" do
  before { login_as :admin }

  describe "GET /admin/users" do
Nihad Abbasov's avatar
Nihad Abbasov committed
7
    before do
gitlabhq's avatar
gitlabhq committed
8 9 10 11 12 13 14
      visit admin_users_path
    end

    it "should be ok" do
      current_path.should == admin_users_path
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
15
    it "should have users list" do
gitlabhq's avatar
gitlabhq committed
16 17 18 19 20
      page.should have_content(@user.email)
      page.should have_content(@user.name)
    end
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
21 22
  describe "GET /admin/users/new" do
    before do
gitlabhq's avatar
gitlabhq committed
23 24
      @password = "123ABC"
      visit new_admin_user_path
25
      fill_in "user_name", with: "Big Bang"
26
      fill_in "user_username", with: "bang"
27 28 29
      fill_in "user_email", with: "bigbang@mail.com"
      fill_in "user_password", with: @password
      fill_in "user_password_confirmation", with: @password
gitlabhq's avatar
gitlabhq committed
30 31
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
32
    it "should create new user" do
33
      expect { click_button "Create user" }.to change {User.count}.by(1)
gitlabhq's avatar
gitlabhq committed
34 35
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
36
    it "should create user with valid data" do
37
      click_button "Create user"
gitlabhq's avatar
gitlabhq committed
38 39 40 41 42
      user = User.last
      user.name.should ==  "Big Bang"
      user.email.should == "bigbang@mail.com"
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
43
    it "should call send mail" do
44
      Notify.should_receive(:new_user_email)
45 46

      User.observers.enable :user_observer do
47
        click_button "Create user"
48
      end
gitlabhq's avatar
gitlabhq committed
49 50
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
51
    it "should send valid email to user with email & password" do
Marin Jankovski's avatar
Marin Jankovski committed
52
      Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
53
      User.observers.enable :user_observer do
54
        click_button "Create user"
55 56 57
        user = User.last
        email = ActionMailer::Base.deliveries.last
        email.subject.should have_content("Account was created")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
58 59
        email.text_part.body.should have_content(user.email)
        email.text_part.body.should have_content(@password)
60
      end
gitlabhq's avatar
gitlabhq committed
61
    end
Marin Jankovski's avatar
Marin Jankovski committed
62 63 64 65

    it "should send valid email to user with email without password when signup is enabled" do
      Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
      User.observers.enable :user_observer do
66
        click_button "Create user"
Marin Jankovski's avatar
Marin Jankovski committed
67 68 69
        user = User.last
        email = ActionMailer::Base.deliveries.last
        email.subject.should have_content("Account was created")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
70 71
        email.text_part.body.should have_content(user.email)
        email.text_part.body.should_not have_content(@password)
Marin Jankovski's avatar
Marin Jankovski committed
72 73
      end
    end
gitlabhq's avatar
gitlabhq committed
74 75
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
76 77
  describe "GET /admin/users/:id" do
    before do
gitlabhq's avatar
gitlabhq committed
78
      visit admin_users_path
Saito's avatar
Saito committed
79
      click_link "#{@user.name}"
gitlabhq's avatar
gitlabhq committed
80 81
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
82
    it "should have user info" do
gitlabhq's avatar
gitlabhq committed
83 84 85 86 87
      page.should have_content(@user.email)
      page.should have_content(@user.name)
    end
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
88 89
  describe "GET /admin/users/:id/edit" do
    before do
90
      @simple_user = create(:user)
gitlabhq's avatar
gitlabhq committed
91 92 93 94
      visit admin_users_path
      click_link "edit_user_#{@simple_user.id}"
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
95
    it "should have user edit page" do
gitlabhq's avatar
gitlabhq committed
96 97 98 99 100
      page.should have_content("Name")
      page.should have_content("Password")
    end

    describe "Update user" do
Nihad Abbasov's avatar
Nihad Abbasov committed
101
      before do
102 103
        fill_in "user_name", with: "Big Bang"
        fill_in "user_email", with: "bigbang@mail.com"
gitlabhq's avatar
gitlabhq committed
104
        check "user_admin"
105
        click_button "Save changes"
gitlabhq's avatar
gitlabhq committed
106 107
      end

Nihad Abbasov's avatar
Nihad Abbasov committed
108
      it "should show page with  new data" do
gitlabhq's avatar
gitlabhq committed
109 110 111 112
        page.should have_content("bigbang@mail.com")
        page.should have_content("Big Bang")
      end

Nihad Abbasov's avatar
Nihad Abbasov committed
113
      it "should change user entry" do
gitlabhq's avatar
gitlabhq committed
114 115 116 117 118 119
        @simple_user.reload
        @simple_user.name.should == "Big Bang"
        @simple_user.is_admin?.should be_true
      end
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
120

121 122 123
  describe "Add new project" do
    before do
      @new_project = create(:project)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
124 125 126
      visit admin_user_path(@user)
    end

127
    it "should create new user" do
128
      select @new_project.name, from: "project_ids"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
129 130 131 132 133
      expect { click_button "Add" }.to change { UsersProject.count }.by(1)
      page.should have_content @new_project.name
      current_path.should == admin_user_path(@user)
    end
  end
gitlabhq's avatar
gitlabhq committed
134
end