diff --git a/app/models/member.rb b/app/models/member.rb index 8f2548d8b..8e33c1fb2 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -14,8 +14,7 @@ class Member < ActiveRecord::Base # Setup accessible (or protected) attributes for your model attr_accessible :login_name, :email, :password, :password_confirmation, - :remember_me, :login, :tos_agreement - # attr_accessible :title, :body + :remember_me, :login, :tos_agreement, :show_email # Virtual attribute for authenticating by either username or email # This is in addition to a real persisted field like 'username' diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 7a6f1943c..05450c0b1 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -11,6 +11,11 @@ = f.email_field :email %span.help-inline If you change your email address you will have to reconfirm + .control-group + .controls + = f.check_box :show_email + Show email publicly on your profile page + %h2 Change password .control-group diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 84b63af5b..071d1956c 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -22,7 +22,7 @@ .control-group .controls = f.check_box :tos_agreement - I agree to the + I agree to the = link_to('Terms of Service', url_for(:action => 'tos', :controller => '/policy')) .form-actions diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 6ed1787fd..dc8cdf754 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -8,7 +8,12 @@ %p = "Member since: #{@member.created_at.to_s(:date)}" - %p Location: Unknown + %p + Location: Unknown + - if @member.show_email + %p + Email: + = mail_to @member.email .span9 .tabbable diff --git a/db/migrate/20130206051328_add_show_email_to_member.rb b/db/migrate/20130206051328_add_show_email_to_member.rb new file mode 100644 index 000000000..b18d3ee3d --- /dev/null +++ b/db/migrate/20130206051328_add_show_email_to_member.rb @@ -0,0 +1,5 @@ +class AddShowEmailToMember < ActiveRecord::Migration + def change + add_column :members, :show_email, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 9ee8655cc..7b1db6ce2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130118043431) do +ActiveRecord::Schema.define(:version => 20130206051328) do create_table "crops", :force => true do |t| t.string "system_name", :null => false @@ -59,6 +59,7 @@ ActiveRecord::Schema.define(:version => 20130118043431) do t.string "login_name" t.string "slug" t.boolean "tos_agreement" + t.boolean "show_email" end add_index "members", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true diff --git a/spec/factories/member.rb b/spec/factories/member.rb index 169499e45..23a3d7fa6 100644 --- a/spec/factories/member.rb +++ b/spec/factories/member.rb @@ -7,20 +7,24 @@ FactoryGirl.define do email { generate(:email) } tos_agreement true confirmed_at Time.now + show_email false factory :no_tos_member do tos_agreement false -# email 'notos@example.com' end factory :unconfirmed_member do confirmed_at nil -# email 'confirmed@example.com' end factory :long_name_member do login_name 'Marmaduke Blundell-Hollinshead-Blundell-Tolemache-Plantagenet-Whistlebinkie, 3rd Duke of Marmoset' -# email 'marmaduke@example.com' + end + + # this member has very loose privacy settings + factory :public_member do + login_name 'NothingToHide' + show_email true end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index bd29cd594..cf5415643 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -29,6 +29,11 @@ describe 'member' do @member.gardens.count.should == 1 end + it "doesn't show email by default" do + @member.save + @member.show_email.should be_false + end + it 'should stringify as the login_name' do @member.to_s.should == 'member1' "#{@member}".should == 'member1' diff --git a/spec/views/devise/registrations/edit_spec.rb b/spec/views/devise/registrations/edit_spec.rb index 25bb6d4c5..8eedcc41a 100644 --- a/spec/views/devise/registrations/edit_spec.rb +++ b/spec/views/devise/registrations/edit_spec.rb @@ -18,9 +18,14 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do rendered.should contain 'Email' end - it 'should have an email section' do - assert_select "h2", "Email address" - end + context 'email section' + it 'has a heading' do + assert_select "h2", "Email address" + end + + it 'shows show_email checkbox' do + assert_select "input[id=member_show_email][type=checkbox]" + end it 'should have a password section' do assert_select "h2", "Change password" diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb index b5f22735e..98718d6fd 100644 --- a/spec/views/members/show.html.haml_spec.rb +++ b/spec/views/members/show.html.haml_spec.rb @@ -41,6 +41,10 @@ describe "members/show" do rendered.should_not contain "Note: these are a random selection" end + it "doesn't show the email address" do + rendered.should_not contain @member.email + end + context "signed in member" do before(:each) do sign_in @member @@ -52,4 +56,15 @@ describe "members/show" do end end + context "public member" do + before(:each) do + @member = FactoryGirl.create(:public_member) + render + end + + it "shows the email address" do + rendered.should contain @member.email + end + end + end