Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
describe AspectsController, :type => :controller do
alice.getting_started = false
alice.save
sign_in :user, alice
@alices_aspect_1 = alice.aspects.where(:name => "generic").first
Dan Hansen
a validé
@alices_aspect_2 = alice.aspects.create(:name => "another aspect")
allow(@controller).to receive(:current_user).and_return(alice)
request.env["HTTP_REFERER"] = 'http://' + request.host
describe "#new" do
it "renders a remote form if remote is true" do
get :new, "remote" => "true"
expect(response).to be_success
expect(response.body).to match(/#{Regexp.escape('data-remote="true"')}/)
end
it "renders a non-remote form if remote is false" do
get :new, "remote" => "false"
expect(response).to be_success
expect(response.body).not_to match(/#{Regexp.escape('data-remote="true"')}/)
end
it "renders a non-remote form if remote is missing" do
get :new
expect(response).to be_success
expect(response.body).not_to match(/#{Regexp.escape('data-remote="true"')}/)
end
end
it "creates an aspect" do
post :create, "aspect" => {"name" => "new aspect"}
expect(alice.reload.aspects.count).to eq(3)
danielgrippi
a validé
it "redirects to the aspect's contact page" do
post :create, "aspect" => {"name" => "new aspect"}
expect(response).to redirect_to(contacts_path(:a_id => Aspect.find_by_name("new aspect").id))
context "with person_id param" do
it "creates a contact if one does not already exist" do
post :create, :format => 'js', :aspect => {:name => "new", :person_id => eve.person.id}
alice.contacts.count
}.by(1)
end
it "adds a new contact to the new aspect" do
post :create, :format => 'js', :aspect => {:name => "new", :person_id => eve.person.id}
expect(alice.aspects.find_by_name("new").contacts.count).to eq(1)
end
it "adds an existing contact to the new aspect" do
post :create, :format => 'js', :aspect => {:name => "new", :person_id => bob.person.id}
expect(alice.aspects.find_by_name("new").contacts.count).to eq(1)
it "does not create an aspect" do
post :create, "aspect" => {"name" => ""}
expect(alice.reload.aspects.count).to eq(2)
it "goes back to the page you came from" do
post :create, "aspect" => {"name" => ""}
expect(response).to redirect_to(:back)
describe "#update" do
before do
@alices_aspect_1 = alice.aspects.create(:name => "Bruisers")
it "doesn't overwrite random attributes" do
Dan Hansen
a validé
params = {"name" => "Bruisers"}
params[:user_id] = new_user.id
put('update', :id => @alices_aspect_1.id, "aspect" => params)
expect(Aspect.find(@alices_aspect_1.id).user_id).to eq(alice.id)
it "should return the name and id of the updated item" do
params = {"name" => "Bruisers"}
put('update', :id => @alices_aspect_1.id, "aspect" => params)
expect(response.body).to eq({ :id => @alices_aspect_1.id, :name => "Bruisers" }.to_json)
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
describe "#destroy" do
before do
@alices_aspect_1 = alice.aspects.create(name: "Contacts")
end
context "with no auto follow back aspect" do
it "destoys the aspect" do
expect(alice.aspects.to_a).to include @alices_aspect_1
post :destroy, id: @alices_aspect_1.id
expect(alice.reload.aspects.to_a).not_to include @alices_aspect_1
end
it "renders a flash message on success" do
post :destroy, id: @alices_aspect_1.id
expect(flash[:notice]).to eq(I18n.t("aspects.destroy.success", name: @alices_aspect_1.name))
expect(flash[:error]).to be_blank
end
end
context "with the aspect set as auto follow back" do
before do
alice.auto_follow_back = true
alice.auto_follow_back_aspect = @alices_aspect_1
alice.save
end
it "destoys the aspect" do
expect(alice.aspects.to_a).to include @alices_aspect_1
post :destroy, id: @alices_aspect_1.id
expect(alice.reload.aspects.to_a).not_to include @alices_aspect_1
end
it "disables auto follow back" do
expect(alice.auto_follow_back).to be(true)
expect(alice.auto_follow_back_aspect).to eq(@alices_aspect_1)
post :destroy, id: @alices_aspect_1.id
expect(alice.auto_follow_back).to be(false)
expect(alice.auto_follow_back_aspect).to eq(nil)
end
it "renders a flash message telling you to set a new auto follow back aspect" do
post :destroy, id: @alices_aspect_1.id
expect(flash[:notice]).to eq(I18n.t("aspects.destroy.success_auto_follow_back", name: @alices_aspect_1.name))
expect(flash[:error]).to be_blank
end
end
end
describe "#toggle_contact_visibility" do
it 'sets contacts visible' do
@alices_aspect_1.contacts_visible = false
@alices_aspect_1.save
xhr :get, :toggle_contact_visibility, :aspect_id => @alices_aspect_1.id
expect(@alices_aspect_1.reload.contacts_visible).to be true
end
it 'sets contacts hidden' do
@alices_aspect_1.contacts_visible = true
@alices_aspect_1.save
xhr :get, :toggle_contact_visibility, :aspect_id => @alices_aspect_1.id
expect(@alices_aspect_1.reload.contacts_visible).to be false