Skip to content

Commit

Permalink
update and iron out user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonv3 committed Apr 8, 2015
1 parent 1ff80fe commit acc0e12
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 54 deletions.
24 changes: 19 additions & 5 deletions app/assets/stylesheets/styles/components/users/_sign_up.css.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.infos{
.infos {
text-align: center;
font-size: 1.2rem;
margin-bottom: 4rem;

.image{
.image {
height: 80px;
margin-bottom: 1rem;
position: relative;
}

img{
img {
margin: 0;
position: absolute;
top: 50%;
Expand All @@ -18,14 +18,28 @@
transform: translate(-50%, -50%)
}

p{
p {
width: 80%;
line-height: 1.2;
color: $of-dark;
margin: 0 auto;
}
}

.sign-in{
input + small {
top: -1rem;
position: relative;
}

.sign-in {
margin-bottom: 4rem;
}

.button-wrapper {
text-align: center;
}

.sign-up {
margin-top: 1rem;
text-align: right;
}
7 changes: 7 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ class UsersController < ApplicationController

def update
authorize current_user

user_settings = {
units: params[:units],
location: params[:location]
}

@outcome = Users::UpdateUser.run(
user: params,
user_setting: user_settings,
id: "#{current_user._id}")

if @outcome.errors
Expand Down
30 changes: 12 additions & 18 deletions app/mutations/users/update_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,29 @@ class UpdateUser < Mutations::Command
hash :user do
optional do
string :display_name
string :location
string :years_experience
string :mailing_list
string :help_list
string :units
string :is_private
end
end
end

# optional do

# end
optional do
hash :user_setting do
optional do
string :location
string :years_experience
string :units
end
end
end

def execute
@user = User.find(id)
if user_setting
@user.user_setting.update_attributes(user_setting)
end
@user.update_attributes(user)
@user.save
# set_valid_params
end

# def set_valid_params
# # TODO: Probably a DRYer way of doing this.
# user.location = location if location.present?
# user.display_name = display_name if display_name.present?
# user.mailing_list = mailing_list if mailing_list.present?
# user.units = units if units.present?
# user.is_private = is_private if is_private.present?
# user.save
# end
end
end
4 changes: 2 additions & 2 deletions app/views/devise/shared/_links.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span class="devise-links">
<div class="devise-links center">
<%- if controller_name != 'sessions' %>
<%= link_to t('application.log_in'), new_session_path(resource_name) %><br/>
<% end -%>
Expand All @@ -25,4 +25,4 @@
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br/>
<% end -%>
<% end -%>
</span>
</div>
11 changes: 8 additions & 3 deletions app/views/devise/shared/_user_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@
<%= f.label :email, I18n.t('users.email_address') %>
<%= f.email_field :email %>
<small id="passwordhelp"><%= t('users.will_send_email') %></small>

<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<% if @user.new_record? %>
<%= f.label :password, I18n.t('users.password') %>
<small id="passwordhelp"><%= t('users.at_least_8_characters') %></small>
<%= f.password_field :password, autocomplete: "off", ariaDescribedby: "passwordhelp" %>
<small id="passwordhelp"><%= t('users.at_least_8_characters') %></small>

<%= f.hidden_field :agree, value: true %><%= f.label :agree, t('users.tos_privacy_html',
tos_url: page_path('tos'),
privacy_url: page_path('privacy') ) %>
privacy_url: page_path('privacy'),
coc_url: page_path('code_of_conduct') ) %>
<% else %>
<%= f.label :current_password, I18n.t('users.current_password') %>
<%= f.password_field :current_password, autocomplete: "off" %>
Expand All @@ -41,7 +44,9 @@
<% end %>
<% if @user.new_record? %>
<%= f.submit I18n.t('users.create_account'), class: 'button submit' %>
<div class="center">
<%= f.submit I18n.t('users.create_account'), class: 'button submit sign-up' %>
</div>
<% else %>
<%= f.submit I18n.t('users.update_account'), class: 'button submit' %>
<% end %>
Expand Down
25 changes: 4 additions & 21 deletions app/views/users/finish.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="finish"
ng-controller="finishCtrl">
<div class="bar-header">
<h1 class="title"><%= t('.welcome', user: current_user.display_name) %></h1>
<h1 class="title"><%= t('.thanks_for_joining') %></h1>
</div>
<div class="row title">
<div class="large-12 columns">
Expand All @@ -27,33 +27,16 @@
</span>
</div>
</div>
<%# TODO: How do we store these? %>
<!-- <div class="row">
<div class="large- columns">
<label for="location">
<%= t('.describe_your_growing_practices') %>
</label>
<small><%= t('.check_all_that_apply') %></small>
</div>
<div class="large-8 columns">
<input id="organic" type="checkbox" name="practices" checked><label for="organic" >Organic</label>
<input id="permaculture" type="checkbox" name="practices"><label for="permaculture">Permaculture</label>
<input id="conventional" type="checkbox" name="practices"><label for="conventional">Conventional</label>
<span class="dropdown">
<input id="hydroponic" type="checkbox" name="practices"><label for="hydroponic">Hydroponic</label>
</span>
</div>
</div> -->
<div class="row">
<div class="large-4 columns">
<label for="location">
<%= t('.units_preference') %>
</label>
</div>
<div class="large-8 columns">
<input type="radio" id="imperial" value="imperial" name="units"><label for="imperial">Imperial</label>
<input type="radio" id="units-imperial" value="imperial" name="units"><label for="units-imperial">Imperial</label>

<input id="metric" type="radio" value="metric" name="units" checked><label for="metric">Metric</label>
<input id="units-metric" type="radio" value="metric" name="units" checked><label for="units-metric">Metric</label>
</div>
</div>
<div class="row">
Expand All @@ -70,7 +53,7 @@

<div class="row">
<div class="large-4 columns">
<label for="location">
<label for="help_sign_up">
<%= t('.help_sign_up') %>
<br/><small><%= t('.help_description') %></small>
</label>
Expand Down
9 changes: 6 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ en:
create: "Create"
share_your_knowledge_with_guide_creation: "Share your knowledge with guide creation"
email_address: "Email Address:"
will_send_email: We'll send you an email to confirm your account.
tos_privacy_html: |
By signing up you agree to the <a href='%{tos_url}'>Terms of Service</a>
and the <a href='%{privacy_url}'>Privacy Policy</a>
By signing up you agree to the <a href='%{tos_url}'>Terms of Service</a>,
<a href='%{privacy_url}'>Privacy Policy</a>, and <a href='%{coc_url}'>
Code of Conduct</a>
is_private: "Check to keep your profile private."
account_information: "Account Information"
display_name: "Display Name:"
password: "Password:"
at_least_8_characters: "At least 8 characters"
at_least_8_characters: Your password should be at least 8 characters long.
need_confirmation: "You need to confirm your account, check your email!"
new_password: "New Password:"
current_password: "Current Password (we need this to confirm your changes)"
Expand All @@ -121,6 +123,7 @@ en:
delete: "Permanently delete account"
finish:
welcome: "Welcome %{user}!"
thanks_for_joining: Thanks for joining! Now just a few more things.
openfarm_works_best_when: "OpenFarm works best when we know the following:"
where_do_you_farm: "Where do you farm or garden?"
city_or_zip: "City or Zip Code is Recommended."
Expand Down
13 changes: 11 additions & 2 deletions spec/features/user_sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@

expect(page).to have_content('Your account was successfully confirmed')

see 'Welcome Rick'
see 'Thanks for joining!'
# TODO: this isn't working
# wait_until_angular_ready
# fill_in :units, with: 'Chicago'
# fill_in :location, with: 'Chicago'
click_button 'Next: Add Garden'

expect(page).to have_content('Your Gardens')
end

it 'should register the user unit preference' do
usr = sign_up_procedure

choose 'units-imperial'

click_button 'Next: Add Garden'
expect(usr.user_setting.units).to eq('imperial')
end

it 'should link to mailchimp if user chooses to be on mailing list' do
usr = sign_up_procedure

Expand Down
5 changes: 5 additions & 0 deletions spec/mutations/users/update_user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Users::UpdateUser do
let(:cg) { Users::UpdateUser }
end

0 comments on commit acc0e12

Please sign in to comment.