Skip to content
Browse files

(+Brian) Removed AdminConstraint entirely and fixed pending specs by …

…removing session override.
  • Loading branch information...
1 parent 7f2e13f commit 613feedbb1352b1043931bd6d64dc99c999f1bc2 @woodhull woodhull committed Aug 28, 2013
View
4 config/routes.rb
@@ -9,7 +9,9 @@
delete "/logout" => "devise/sessions#destroy"
end
- mount Sidekiq::Web => '/admin/sidekiq', :constraints => lambda {|req| AdminConstraint.new.matches?(req) }
+ authenticate :user, lambda { |u| u.is_super_user || u.is_admin } do
+ mount Sidekiq::Web => '/admin/sidekiq'
+ end
get "privacy/index"
View
7 lib/admin_constraint.rb
@@ -1,7 +0,0 @@
-class AdminConstraint
- def matches?(request)
- return false if request.session[:user_id].blank?
- u = User.where(id: request.session[:user_id]).first
- u.present? && ( u.is_super_user || u.is_admin )
- end
-end
View
17 spec/controllers/petitions_controller_spec.rb
@@ -234,19 +234,17 @@ def valid_attributes
describe "with valid params" do
before(:each) do
- @logged_in_user = create(:user)
+ @logged_in_user = create(:super_user)
sign_in @logged_in_user
- post :create, {petition: valid_attributes}, {user_id: @logged_in_user.id}
+ post :create, petition: valid_attributes
end
describe "the newly created petition" do
- pending "Broken since switch to Devise"
- # subject { assigns(:petition) }
- # it { should be_persisted }
- # it { should be_a(Petition) }
- # its(:owner) { should == @logged_in_user}
+ subject { assigns(:petition) }
+ it { response.inspect; should be_persisted }
+ it { should be_a(Petition) }
+ its(:owner) { should == @logged_in_user}
end
its(:response) do
- pending "Broken since switch to Devise"
response.should redirect_to(Petition.last)
end
end
@@ -273,9 +271,8 @@ def valid_attributes
it "persists images" do
image_attributes = { "petition_images_attributes" => { "1354739331381" => {"url" => "image.jpg"} } }
- pending "Broken since switch to Devise"
PetitionImageDownloader.should_receive(:download) {|image| image.url.should == 'image.jpg' }
- post :create, {petition: valid_attributes.merge(image_attributes)}, {user_id: @logged_in_user.id}
+ post :create, petition: valid_attributes.merge(image_attributes)
end
end
end
View
67 spec/controllers/sessions_controller_spec.rb
@@ -1,67 +0,0 @@
-describe SessionsController do
-
- pending "Disabled after switching to Devise. Should be deleted or fixed..."
-
-# describe "POST 'create'" do
-# context "user logs in with valid credentials" do
-# before(:each) do
-# @user = create(:user, password:"opensesame", email: "bob@here.com")
-# post :create, user_session: { email: "bob@here.com", password:"opensesame"}
-# end
-# it "adds the user id to the session" do
-# # session[:user_id].should == @user.id
-# current_user.id.should == @user.id
-# end
-# it { should redirect_to admin_dashboard_path }
-# end
-# context "user attempts to login with wrong password" do
-# before(:each) do
-# @user = create(:user, email: "bob@here.com", password: "supersecret")
-# post :create, new_session: {email: "bob@here.com", password:"closesesame"}
-# end
-# it "redirects to the login page" do
-# response.should redirect_to login_path
-# end
-# it "does not add user id to the session" do
-# # session[:user_id].should be_nil
-# current_user.should be_nil
-# end
-# it "displays message to user" do
-# flash.now[:error].should == "Invalid username or password"
-# end
-# end
-# context "user attempts to login with wrong email" do
-# before(:each) do
-# @user = create(:user, email:"bob@ajob.com", password: "opensesame")
-# post :create, new_session: {email: "jim@here.com", password:"opensesame"}
-# end
-# it "redirects to the login page" do
-# response.should redirect_to login_path
-# end
-# it "does not add user id to the session" do
-# # session[:user_id].should be_nil
-# current_user.should be_nil
-# end
-# it "displays message to user" do
-# flash.now[:error].should == "Invalid username or password"
-# end
-# end
-# end
-
-# describe "DELETE 'destroy'" do
-# context "user logs out" do
-# before(:each) do
-# @user = create(:user)
-# session[:user_id] = @user.id
-# delete "destroy", :id => @user.id
-# end
-# it "resets session" do
-# session[:user_id].should be_nil
-# end
-# it { should redirect_to root_path }
-# it "displays message logged out message to user" do
-# flash.now[:notice].should == "Logged out!"
-# end
-# end
-# end
-end

0 comments on commit 613feed

Please sign in to comment.
Something went wrong with that request. Please try again.