adds edition/management of officials to admin zone
This commit is contained in:
78
spec/features/admin/officials_spec.rb
Normal file
78
spec/features/admin/officials_spec.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin officials' do
|
||||
|
||||
background do
|
||||
@citizen = create(:user, first_name: "Citizen", last_name: "Kane")
|
||||
@official = create(:user, official_position: "Mayor", official_level: 5)
|
||||
@admin = create(:administrator)
|
||||
login_as(@admin.user)
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
visit admin_officials_path
|
||||
|
||||
expect(page).to have_content @official.name
|
||||
expect(page).to_not have_content @citizen.name
|
||||
expect(page).to have_content @official.official_position
|
||||
expect(page).to have_content @official.official_level
|
||||
end
|
||||
|
||||
scenario 'Edit an official' do
|
||||
visit admin_officials_path
|
||||
click_link @official.name
|
||||
|
||||
expect(current_path).to eq(edit_admin_official_path(@official))
|
||||
|
||||
expect(page).to_not have_content @citizen.name
|
||||
expect(page).to have_content @official.name
|
||||
expect(page).to have_content @official.email
|
||||
|
||||
fill_in 'user_official_position', with: 'School Teacher'
|
||||
select '3', from: 'user_official_level'
|
||||
click_button 'Update User'
|
||||
|
||||
expect(page).to have_content 'Official position saved!'
|
||||
|
||||
visit admin_officials_path
|
||||
|
||||
expect(page).to have_content @official.name
|
||||
expect(page).to have_content 'School Teacher'
|
||||
expect(page).to have_content '3'
|
||||
end
|
||||
|
||||
scenario 'Create an official' do
|
||||
visit admin_officials_path
|
||||
fill_in 'email', with: @citizen.email
|
||||
click_button 'Search'
|
||||
|
||||
expect(current_path).to eq(search_admin_officials_path)
|
||||
expect(page).to_not have_content @official.name
|
||||
|
||||
click_link @citizen.name
|
||||
|
||||
fill_in 'user_official_position', with: 'Hospital manager'
|
||||
select '4', from: 'user_official_level'
|
||||
click_button 'Update User'
|
||||
|
||||
expect(page).to have_content 'Official position saved!'
|
||||
|
||||
visit admin_officials_path
|
||||
|
||||
expect(page).to have_content @official.name
|
||||
expect(page).to have_content @citizen.name
|
||||
expect(page).to have_content 'Hospital manager'
|
||||
expect(page).to have_content '4'
|
||||
end
|
||||
|
||||
scenario 'Destroy' do
|
||||
visit edit_admin_official_path(@official)
|
||||
|
||||
click_link "Remove 'Official' condition"
|
||||
|
||||
expect(page).to have_content 'User is not an official anymore'
|
||||
expect(current_path).to eq(admin_officials_path)
|
||||
expect(page).to_not have_content @citizen.name
|
||||
expect(page).to_not have_content @official.name
|
||||
end
|
||||
end
|
||||
@@ -169,4 +169,18 @@ describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe "self.with_email" do
|
||||
it "find users by email" do
|
||||
user1 = create(:user, email: "larry@madrid.es")
|
||||
user2 = create(:user, email: "bird@madrid.es")
|
||||
search = User.with_email("larry@madrid.es")
|
||||
expect(search.size).to eq(1)
|
||||
expect(search.first).to eq(user1)
|
||||
end
|
||||
|
||||
it "returns no results if no email provided" do
|
||||
expect(User.with_email(" ").size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user