Change your factories.rb
like this:
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "Person #{n}" }
sequence(:email) { |n| "person_#{n}@example.com" }
password "foobar"
password_confirmation "foobar"
factory :admin do
admin true
end
end
end
And create admin user like this:
let(:admin) { FactoryGirl.create(:admin) }
I found two error syntax in your describe "delete link"
:
it { should have_link('delete', href: users_path(User.first)) }
...
it { should_not have_link('delete', href: users_path(admin))}
it should be:
it { should have_link('delete', href: user_path(User.first)) }
...
it { should_not have_link('delete', href: user_path(admin))}
Update
This code in _user.html.erb
will check if users is not admin, they will have a delete link:
<% if current_user.admin? && !current_user?(user) %>
| <%= link_to "delete", user, method: :delete, data: { confirm: "You sure?" } %>
<% end %>