Module: Clearance::Test::Functional::UsersControllerTest

Defined in:
lib/clearance/test/functional/users_controller_test.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/clearance/test/functional/users_controller_test.rb', line 6

def self.included(base)
  base.class_eval do
    public_context do

      context "on GET to /users/new" do
        setup { get :new }
        should_respond_with :success
        should_render_template :new
        should_not_set_the_flash
        should_have_form :action => "users_path",
          :method => :post,
          :fields => { :email => :text,
            :password => :password,
            :password_confirmation => :password }

        context "with params" do
          setup do
            @email = '[email protected]'
            get :new, :user => {:email => @email}
          end

          should_assign_to :user
          should "set the @user's params" do
            assert_equal @email, assigns(:user).email
          end
        end
      end

      context "on POST to /users" do
        setup do
          post :create, :user => {
            :email => Factory.next(:email),
            :password => 'skerit',
            :password_confirmation => 'skerit'
          }
        end
    
        should_set_the_flash_to /confirm/i
        should_redirect_to "@controller.send(:url_after_create)"
        should_assign_to :user
        should_change 'User.count', :by => 1
      end

    end

    logged_in_user_context do
      context "GET to new" do
        setup { get :new }
        should_redirect_to 'root_url'
      end

      context "POST to create" do
        setup { post :create, :user => {} }
        should_redirect_to 'root_url'
      end

      should_filter_params :password
    end
  end
end