aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/admin_spam_addresses_controller_spec.rb
blob: a1e43415998d6cbd4821bb11df11712d7a90578a (plain)
1
2
3
4
5
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require 'spec_helper'

describe AdminSpamAddressesController do
    render_views
    before { basic_auth_login @request }

    describe :index do

        it 'lists the spam addresses' do
            3.times { FactoryGirl.create(:spam_address) }
            get :index
            assigns(:spam_addresses).should == SpamAddress.all
        end

        it 'creates a new spam address for the form' do
            get :index
            expect(assigns(:spam_address)).to be_a_new(SpamAddress)
        end

        it 'renders the index template' do
            get :index
            expect(response).to render_template('index')
        end

    end

    describe :create do

        let(:spam_params) { FactoryGirl.attributes_for(:spam_address) }

        it 'creates a new spam address with the given parameters' do
            post :create, :spam_address => spam_params
            assigns(:spam_address).email.should == spam_params[:email]
            assigns(:spam_address).should be_persisted
        end

        it 'redirects to the index action if successful' do
            SpamAddress.any_instance.stub(:save).and_return(true)
            post :create, :spam_address => spam_params
            expect(response).to redirect_to(admin_spam_addresses_path)
        end

        it 'notifies the admin the spam address has been created' do
            SpamAddress.any_instance.stub(:save).and_return(true)
            post :create, :spam_address => spam_params
            msg = "#{ spam_params[:email] } has been added to the spam addresses list"
            flash[:notice].should == msg
        end

        it 'renders the index action if the address could not be saved' do
            SpamAddress.any_instance.stub(:save).and_return(false)
            post :create, :spam_address => spam_params
            expect(response).to render_template('index')
        end

        it 'collects the spam addresses if the address could not be saved' do
            3.times { FactoryGirl.create(:spam_address) }
            SpamAddress.any_instance.stub(:save).and_return(false)
            post :create, :spam_address => spam_params
            assigns(:spam_addresses).should == SpamAddress.all
        end

    end

    describe :delete do

        before(:each) do
            @spam = FactoryGirl.create(:spam_address)
            delete :destroy, :id => @spam.id
        end

        it 'finds the spam address to delete' do
            assigns(:spam_address).should == @spam
        end

        it 'destroys the spam address' do
            assigns(:spam_address).should be_destroyed
        end

        it 'tells the admin the spam address has been deleted' do
            msg = "#{ @spam.email } has been removed from the spam addresses list"
            flash[:notice].should == msg
        end

        it 'redirects to the index action' do
            expect(response).to redirect_to(admin_spam_addresses_path)
        end

    end

end