From dad64d41fbdc8691d1e53acdaa5466693d587151 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 20 May 2013 12:57:35 +1000 Subject: [PATCH] show account status/upgrade button in various places --- app/models/account_type.rb | 4 ++++ app/models/member.rb | 13 +++++++++---- app/views/home/index.html.haml | 8 ++++++++ app/views/members/show.html.haml | 16 ++++++++++++---- spec/views/home/index_spec.rb | 8 ++++++++ spec/views/members/show.html.haml_spec.rb | 10 +++++++++- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/app/models/account_type.rb b/app/models/account_type.rb index 8aaa4f752..dc464707b 100644 --- a/app/models/account_type.rb +++ b/app/models/account_type.rb @@ -1,4 +1,8 @@ class AccountType < ActiveRecord::Base attr_accessible :is_paid, :is_permanent_paid, :name has_many :products + + def to_s + name + end end diff --git a/app/models/member.rb b/app/models/member.rb index 1b6b04009..aa3387a43 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -13,6 +13,7 @@ class Member < ActiveRecord::Base has_many :authentications has_many :orders has_one :account + has_one :account_type, :through => :account default_scope order("lower(login_name) asc") scope :confirmed, where('confirmed_at IS NOT NULL') @@ -113,10 +114,14 @@ class Member < ActiveRecord::Base end def is_paid? - if account.account_type.is_permanent_paid - return true - elsif account.account_type.is_paid and account.paid_until >= Time.zone.now - return true + if account.account_type # it might be nil if you've never had one + if account.account_type.is_permanent_paid + return true + elsif account.account_type.is_paid and account.paid_until >= Time.zone.now + return true + else + return false + end else return false end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 7b33f1506..8819e544e 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -27,6 +27,14 @@ = link_to 'Add', new_garden_path, :class => 'btn btn-mini' .span4 + %p + Your account: + %strong + = current_member.account_type || "Free" + account + %br/ + - if current_member == current_member && !current_member.is_paid? + = link_to "Upgrade and Support Growstuff", shop_path, :class => 'btn btn-primary' - if current_member.has_role?(:admin) %p %b You are an ADMIN USER. diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 44ec0aa5f..8da927ede 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -15,6 +15,14 @@ %strong Member since: = @member.created_at.to_s(:date) + %p + %strong Account type: + = @member.account_type || "Free" + account + + - if @member == current_member && !@member.is_paid? + = link_to "Upgrade", shop_path, :class => 'btn btn-primary btn-mini' + - if @twitter_auth || @flickr_auth || @member.show_email %h4 Contact @@ -42,12 +50,12 @@ = @member.location %br/ = link_to 'Find members near here', nearby_members_path(:location => @member.location) - %p - - if current_member == @member - %p - = link_to 'Edit Settings', "edit", :class => 'btn btn-mini' .span9 + %p + - if can? :update, @member + %p + = link_to 'Edit your profile', "edit", :class => 'btn btn-primary' .tabbable %ul.nav.nav-tabs - first_garden = true diff --git a/spec/views/home/index_spec.rb b/spec/views/home/index_spec.rb index e123927f5..49f9e5cf1 100644 --- a/spec/views/home/index_spec.rb +++ b/spec/views/home/index_spec.rb @@ -74,6 +74,14 @@ describe 'home/index.html.haml', :type => "view" do assert_select "a[href=#{url_for(@post)}]" end + it 'shows account type' do + rendered.should contain "Free account" + end + + it 'shows upgrade account button' do + rendered.should contain "Upgrade" + end + it 'shows admin status' do rendered.should contain "You are an ADMIN USER" end diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb index aab5be98b..4c3c66e15 100644 --- a/spec/views/members/show.html.haml_spec.rb +++ b/spec/views/members/show.html.haml_spec.rb @@ -18,6 +18,10 @@ describe "members/show" do rendered.should contain @time.strftime("%B %d, %Y") end + it "shows account type" do + rendered.should contain "Free account" + end + it "contains a gravatar icon" do assert_select "img", :src => /gravatar\.com\/avatar/ end @@ -106,7 +110,11 @@ describe "members/show" do end it "contains an edit settings button" do - rendered.should contain "Edit Settings" + rendered.should contain "Edit your profile" + end + + it "asks you to upgrade your account" do + rendered.should contain "Upgrade" end it "contains no send message button" do