admin_users_spec.rb 4.06 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

36 37 38 39 40 41 42 43
    it "should apply defaults to user" do
      click_button "Create user"
      user = User.last
      user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
      user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
      user.can_create_team.should == Gitlab.config.gitlab.default_can_create_team
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
44
    it "should create user with valid data" do
45
      click_button "Create user"
gitlabhq's avatar
gitlabhq committed
46 47 48 49 50
      user = User.last
      user.name.should ==  "Big Bang"
      user.email.should == "bigbang@mail.com"
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
51
    it "should call send mail" do
52
      Notify.should_receive(:new_user_email)
53 54

      User.observers.enable :user_observer do
55
        click_button "Create user"
56
      end
gitlabhq's avatar
gitlabhq committed
57 58
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
59
    it "should send valid email to user with email & password" do
Marin Jankovski's avatar
Marin Jankovski committed
60
      Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
61
      User.observers.enable :user_observer do
62
        click_button "Create user"
63 64 65
        user = User.last
        email = ActionMailer::Base.deliveries.last
        email.subject.should have_content("Account was created")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
66 67
        email.text_part.body.should have_content(user.email)
        email.text_part.body.should have_content(@password)
68
      end
gitlabhq's avatar
gitlabhq committed
69
    end
Marin Jankovski's avatar
Marin Jankovski committed
70 71 72 73

    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
74
        click_button "Create user"
Marin Jankovski's avatar
Marin Jankovski committed
75 76 77
        user = User.last
        email = ActionMailer::Base.deliveries.last
        email.subject.should have_content("Account was created")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
78 79
        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
80 81
      end
    end
gitlabhq's avatar
gitlabhq committed
82 83
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
84 85
  describe "GET /admin/users/:id" do
    before do
gitlabhq's avatar
gitlabhq committed
86
      visit admin_users_path
Saito's avatar
Saito committed
87
      click_link "#{@user.name}"
gitlabhq's avatar
gitlabhq committed
88 89
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
90
    it "should have user info" do
gitlabhq's avatar
gitlabhq committed
91 92 93 94 95
      page.should have_content(@user.email)
      page.should have_content(@user.name)
    end
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
96 97
  describe "GET /admin/users/:id/edit" do
    before do
98
      @simple_user = create(:user)
gitlabhq's avatar
gitlabhq committed
99 100 101 102
      visit admin_users_path
      click_link "edit_user_#{@simple_user.id}"
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
103
    it "should have user edit page" do
gitlabhq's avatar
gitlabhq committed
104 105 106 107 108
      page.should have_content("Name")
      page.should have_content("Password")
    end

    describe "Update user" do
Nihad Abbasov's avatar
Nihad Abbasov committed
109
      before do
110 111
        fill_in "user_name", with: "Big Bang"
        fill_in "user_email", with: "bigbang@mail.com"
gitlabhq's avatar
gitlabhq committed
112
        check "user_admin"
113
        click_button "Save changes"
gitlabhq's avatar
gitlabhq committed
114 115
      end

Nihad Abbasov's avatar
Nihad Abbasov committed
116
      it "should show page with  new data" do
gitlabhq's avatar
gitlabhq committed
117 118 119 120
        page.should have_content("bigbang@mail.com")
        page.should have_content("Big Bang")
      end

Nihad Abbasov's avatar
Nihad Abbasov committed
121
      it "should change user entry" do
gitlabhq's avatar
gitlabhq committed
122 123 124 125 126 127
        @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
128

129 130 131
  describe "Add new project" do
    before do
      @new_project = create(:project)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
132 133 134
      visit admin_user_path(@user)
    end

135
    it "should create new user" do
136
      select @new_project.name, from: "project_ids"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
137 138 139 140 141
      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
142
end