mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 16:58:35 -04:00
24
app/controllers/registrations_controller.rb
Normal file
24
app/controllers/registrations_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# we need this subclass so that Devise doesn't force people to change their
|
||||
# password every time they want to edit their settings. Code copied from
|
||||
# https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password
|
||||
|
||||
class RegistrationsController < Devise::RegistrationsController
|
||||
def update
|
||||
# required for settings form to submit when password is left blank
|
||||
if params[:member][:password].blank?
|
||||
params[:member].delete("password")
|
||||
params[:member].delete("password_confirmation")
|
||||
params[:member].delete("current_password")
|
||||
end
|
||||
|
||||
@member = Member.find(current_member.id)
|
||||
if @member.update_attributes(params[:member])
|
||||
set_flash_message :notice, :updated
|
||||
# Sign in the member bypassing validation in case his password changed
|
||||
sign_in @member, :bypass => true
|
||||
redirect_to after_update_path_for(@member)
|
||||
else
|
||||
render "edit"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,37 +1,34 @@
|
||||
- content_for :title, "Edit " + resource_name.to_s.humanize
|
||||
- content_for :title, "Settings for #{current_member.login_name}"
|
||||
|
||||
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
|
||||
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-horizontal' }) do |f|
|
||||
= devise_error_messages!
|
||||
|
||||
%div
|
||||
= f.label :email
|
||||
%br
|
||||
= f.email_field :email
|
||||
%h2 Email address
|
||||
|
||||
%div
|
||||
= f.label :password
|
||||
%i (leave blank if you don't want to change it)
|
||||
%br
|
||||
= f.password_field :password, :autocomplete => "off"
|
||||
.control-group
|
||||
= f.label :email, :class => 'control-label'
|
||||
.controls
|
||||
= f.email_field :email
|
||||
%span.help-inline If you change your email address you will have to reconfirm
|
||||
|
||||
%div
|
||||
= f.label :password_confirmation
|
||||
%br
|
||||
= f.password_field :password_confirmation
|
||||
%h2 Change password
|
||||
|
||||
%div
|
||||
= f.label :current_password
|
||||
%i (we need your current password to confirm your changes)
|
||||
%br
|
||||
= f.password_field :current_password
|
||||
.control-group
|
||||
= f.label :password, :class => 'control-label'
|
||||
.controls
|
||||
= f.password_field :password, :autocomplete => "off"
|
||||
%span.help-inline Leave blank if you don't want to change your password
|
||||
|
||||
%div
|
||||
= f.submit "Update"
|
||||
.control-group
|
||||
= f.label :password_confirmation, :class => 'control-label'
|
||||
.controls= f.password_field :password_confirmation
|
||||
|
||||
%h3 Cancel my account
|
||||
.control-group
|
||||
= f.label :current_password, :class => 'control-label'
|
||||
.controls
|
||||
= f.password_field :current_password
|
||||
|
||||
%p
|
||||
Unhappy?
|
||||
= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete.
|
||||
.form-actions
|
||||
= f.submit "Update", :class => 'btn'
|
||||
|
||||
= link_to "Back", :back
|
||||
=f.hidden_field(:tos_agreement, :value => true)
|
||||
|
||||
@@ -17,8 +17,14 @@
|
||||
%li= link_to("Plant something", new_planting_path)
|
||||
%li.divider-vertical
|
||||
- if member_signed_in?
|
||||
%li= link_to current_member.login_name, member_path(current_member)
|
||||
%li= link_to "Log out", destroy_member_session_path, :method => :delete
|
||||
%li.dropdown<
|
||||
%a.dropdown-toggle{'data-toggle' => 'dropdown', :href => member_path(current_member)}
|
||||
= current_member.login_name
|
||||
%b.caret
|
||||
%ul.dropdown-menu
|
||||
%li= link_to "Profile", member_path(current_member)
|
||||
%li= link_to "Settings", edit_member_registration_path
|
||||
%li= link_to "Sign out", destroy_member_session_path, :method => :delete
|
||||
- else
|
||||
%li.pull-right= link_to 'Sign up', new_member_registration_path
|
||||
%li.pull-right= link_to 'Log in', new_member_session_path
|
||||
%li.pull-right= link_to 'Sign in', new_member_session_path
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Growstuff::Application.routes.draw do
|
||||
devise_for :members
|
||||
devise_for :members, :controllers => { :registrations => "registrations" }
|
||||
|
||||
resources :plantings
|
||||
resources :gardens
|
||||
|
||||
@@ -3,14 +3,14 @@ require 'spec_helper'
|
||||
describe MembersController do
|
||||
|
||||
before :each do
|
||||
@member1 = FactoryGirl.create(:member)
|
||||
@posts = [ FactoryGirl.create(:post, :author => @member1) ]
|
||||
@member = FactoryGirl.create(:member)
|
||||
@posts = [ FactoryGirl.create(:post, :author => @member) ]
|
||||
end
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns only confirmed members as @member1s" do
|
||||
it "assigns only confirmed members as @members" do
|
||||
get :index, {}
|
||||
assigns(:members).should eq([@member1])
|
||||
assigns(:members).should eq([@member])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,18 +22,18 @@ describe MembersController do
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested member as @member1" do
|
||||
get :show, {:id => @member1.id}
|
||||
assigns(:member).should eq(@member1)
|
||||
it "assigns the requested member as @member" do
|
||||
get :show, {:id => @member.id}
|
||||
assigns(:member).should eq(@member)
|
||||
end
|
||||
|
||||
it "does NOT provide JSON for member profile" do
|
||||
get :show, { :id => @member1.id , :format => 'json' }
|
||||
get :show, { :id => @member.id , :format => 'json' }
|
||||
response.should_not be_success
|
||||
end
|
||||
|
||||
it "assigns @posts with the member's posts" do
|
||||
get :show, {:id => @member1.id}
|
||||
get :show, {:id => @member.id}
|
||||
assigns(:posts).should eq(@posts)
|
||||
end
|
||||
|
||||
@@ -50,10 +50,11 @@ describe MembersController do
|
||||
|
||||
describe "GET member's RSS feed" do
|
||||
it "returns an RSS feed" do
|
||||
get :show, { :id => @member1.to_param, :format => "rss" }
|
||||
get :show, { :id => @member.to_param, :format => "rss" }
|
||||
response.should be_success
|
||||
response.should render_template("members/show")
|
||||
response.content_type.should eq("application/rss+xml")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -86,7 +86,7 @@ describe PostsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT post" do
|
||||
describe "PUT update" do
|
||||
describe "with valid params" do
|
||||
it "updates the requested post" do
|
||||
post = Post.create! valid_attributes
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'devise/registrations/edit.html.erb', :type => "view" do
|
||||
describe 'devise/registrations/edit.html.haml', :type => "view" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@view.stub(:resource).and_return(Member.new)
|
||||
controller.stub(:current_user) { nil }
|
||||
@member = FactoryGirl.create(:member)
|
||||
controller.stub(:current_member) { @member }
|
||||
@view.stub(:resource).and_return(@member)
|
||||
@view.stub(:resource_name).and_return("member")
|
||||
@view.stub(:resource_class).and_return(Member)
|
||||
@view.stub(:devise_mapping).and_return(Devise.mappings[:member])
|
||||
@@ -13,7 +16,15 @@ describe 'devise/registrations/edit.html.erb', :type => "view" do
|
||||
|
||||
it 'should have some fields' do
|
||||
rendered.should contain 'Email'
|
||||
rendered.should contain 'Cancel my account'
|
||||
end
|
||||
|
||||
it 'should have an email section' do
|
||||
assert_select "h2", "Email address"
|
||||
end
|
||||
|
||||
it 'should have a password section' do
|
||||
assert_select "h2", "Change password"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,8 +8,8 @@ describe 'layouts/_footer.html.haml', :type => "view" do
|
||||
|
||||
it 'should have links in footer' do
|
||||
rendered.should contain 'About'
|
||||
assert_select("a[href=#{'/policy/tos'}]", 'Terms of Service')
|
||||
assert_select("a[href=#{'/policy/community'}]", 'Community Guidelines')
|
||||
assert_select("a[href=/policy/tos]", 'Terms of Service')
|
||||
assert_select("a[href=/policy/community]", 'Community Guidelines')
|
||||
rendered.should contain 'License'
|
||||
rendered.should contain 'Github'
|
||||
rendered.should contain 'Mailing list'
|
||||
|
||||
@@ -15,7 +15,7 @@ describe 'layouts/application.html.haml', :type => "view" do
|
||||
|
||||
it 'should have signup/login links' do
|
||||
rendered.should contain 'Sign up'
|
||||
rendered.should contain 'Log in'
|
||||
rendered.should contain 'Sign in'
|
||||
end
|
||||
|
||||
end
|
||||
@@ -41,8 +41,16 @@ describe 'layouts/application.html.haml', :type => "view" do
|
||||
rendered.should contain 'Plant something'
|
||||
end
|
||||
|
||||
it "should show member's name" do
|
||||
assert_select("a[href=/members/#{@member.login_name}]", "Profile")
|
||||
end
|
||||
|
||||
it "should show settings link" do
|
||||
assert_select "a[href=/members/edit]", "Settings"
|
||||
end
|
||||
|
||||
it 'should show logout link' do
|
||||
rendered.should contain 'Log out'
|
||||
rendered.should contain 'Sign out'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user