Skip to content

Commit

Permalink
edit_profile feature spec and factory for modified_profile_user
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Rosas committed Nov 11, 2014
1 parent def9fe2 commit b63f3eb
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/views/sidebar/edit_profile.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= form_for resource, :as => resource_name, :url => registration_path(resource_name), :html => {:id => "edit_form", :method => :put} do |f|
= f.hidden_field "id"
= render :partial => "user_email", locals: {f: f}
%h2
%h2
= t("labels.shipping_info_heading")
= render :partial => "user_name", locals: {f: f}
= render :partial => "user_address", locals: {f: f}
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_gender.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
= image_tag "lock.png", :class => "lock", :alt => t("captions.private"), :title => t("captions.private")
.radio
%label.radio
= f.radio_button :gender, "male"
= f.radio_button :gender, "male"
= t("labels.male")
%label.radio
= f.radio_button :gender, "female"
Expand Down
18 changes: 18 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,23 @@
name { Faker::Name.name }
email { Faker::Internet.email }
password { Faker::Internet.password(8) }

factory :modified_profile_user do
address_1 { Faker::Address.street_address }
address_2 { Faker::Address.secondary_address }
city { Faker::Address.city }
state { Faker::Address.state_abbr }
zip { Faker::Address.zip_code }
yob { 1900 + rand(100) }
gender { rand(2) == 0 ? 'male' : 'female' }
ethnicity { [rand(2) == 0 ? 'caucasian' : 'other'] }
yearsInMinneapolis { rand(50) }
rentOrOwn { rand(2) == 0 ? 'rent' : 'own' }
previousTreeWateringExperience { rand(2) == 0 ? false : true }
previousEnvironmentalActivities { rand(2) == 0 ? false : true }
valueForestryWork { rand(9) + 1 }
heardOfAdoptATreeVia { ['other'] }
end
end

end
83 changes: 83 additions & 0 deletions spec/features/edit_profile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
require 'rails_helper'

shared_examples "user profile form" do
describe "user info" do
it "populates the form" do |user|
within '.sidebar #edit_form.edit_user' do
user = subject
expect(page).to have_field 'Email address', with: user.email
expect(page).to have_field 'Name (visible to others)', with: user.name
expect(page).to have_field 'Address Line 1', with: user.address_1
expect(page).to have_field 'Address Line 2', with: user.address_2
expect(page).to have_field 'City', with: user.city
expect(page).to have_field 'State', with: user.state
expect(page).to have_field 'ZIP', with: user.zip
expect(page).to have_content 'Survey'
expect(page).to have_field 'user_yob', with: user.yob

expect(page).to have_field 'user_awareness_code',
with: user.awareness_code
expect(page).to have_field 'user_yearsInMinneapolis',
with: user.yearsInMinneapolis

if user.gender
expect(page).to have_checked_field 'user[gender]', with: user.gender
end

if user.ethnicity
expect(page).to have_checked_field 'user[ethnicity][]',
with: user.ethnicity[0]
end

if user.rentOrOwn
expect(page).to have_checked_field 'user[rentOrOwn]',
with: user.rentOrOwn
end

if user.heardOfAdoptATreeVia
expect(page).to have_checked_field 'user[heardOfAdoptATreeVia][]',
with: user.heardOfAdoptATreeVia[0]
end

if user.previousTreeWateringExperience
expect(page).to have_checked_field 'user[previousTreeWateringExperience]',
with: user.previousTreeWateringExperience
end

if user.previousEnvironmentalActivities
expect(page).to have_checked_field 'user[previousEnvironmentalActivities]',
with: user.previousEnvironmentalActivities
end

if user.valueForestryWork
expect(page).to have_checked_field 'user[valueForestryWork]',
with: user.valueForestryWork
end
end
end
end
end

describe 'Edit Profile', js: true do
context "New User" do
subject { create(:user) }

before do
sign_in(subject)
find_link('Edit profile').click
end

it_behaves_like "user profile form"
end

context "Modified User" do
subject { create(:modified_profile_user) }

before do
sign_in(subject)
find_link('Edit profile').click
end

it_behaves_like "user profile form"
end
end

0 comments on commit b63f3eb

Please sign in to comment.