prettified signed-in homepage; tests still needed

This commit is contained in:
Skud
2013-03-05 22:20:13 +11:00
parent 204b5cdf8c
commit 3c0e467da1
6 changed files with 71 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ class Member < ActiveRecord::Base
has_many :posts, :foreign_key => 'author_id'
has_many :comments, :foreign_key => 'author_id'
has_many :gardens, :foreign_key => 'owner_id'
has_many :plantings, :through => :gardens
has_many :forums, :foreign_key => 'owner_id'
has_and_belongs_to_many :roles

View File

@@ -6,6 +6,7 @@ class Planting < ActiveRecord::Base
belongs_to :garden
belongs_to :crop
belongs_to :forum
def planting_slug
"#{owner.login_name}-#{garden.name}-#{crop.system_name}".downcase.gsub(' ', '-')

View File

@@ -2,23 +2,71 @@
%h1= "Welcome, #{current_member.login_name}"
%p
%b Your profile:
=link_to current_member, current_member
.row
.span6
%p
%b Your profile:
=link_to current_member, current_member
%p
%b Your gardens:
%p
%b Your location:
= current_member.location ? current_member.location : 'Not set'
%small
= link_to "Edit", edit_registration_path(current_member)
%ul.inline
- current_member.gardens.each do |g|
%li= link_to g.name, g
%ul.inline
%li.first
%b Your gardens:
- current_member.gardens.each do |g|
%li= link_to g.name, g
- if can? :create, Garden
%li= link_to 'Add a garden', new_garden_path
.span6
- if current_member.has_role?(:admin)
%p
%b You are an ADMIN USER.
%p
%b Recently planted:
%ul
%li coming soon
- if current_member.forums
%p
%b Forums you administer:
%ul
- current_member.forums.each do |f|
%li= link_to f.name, f
%h2 Recent comments on your posts
.row
.span6
%h2 Your recent plantings
- if current_member.plantings.count > 0
%ul
- current_member.plantings.limit(10).each do |p|
%li
= link_to "#{p.crop.system_name} in #{p.location}", p
- if p.planted_at
on
= p.planted_at.to_s(:date)
- else
%p None yet.
- if can? :create, Planting
%p= link_to "Plant something", new_planting_path, :class => 'btn btn-primary'
.span6
%h2 Your recent posts
- if current_member.posts.count > 0
%ul
- current_member.posts.limit(10).each do |p|
%li
= link_to p.subject, p
- if p.forum
in
= link_to p.forum.name, p.forum
on
= p.created_at.to_s(:date)
- else
%p None yet.
- if can? :create, Planting
%p= link_to "Post something", new_post_path, :class => 'btn btn-primary'
.span6
- else

View File

@@ -12,10 +12,6 @@
%li= link_to "Members", members_path
%li= link_to "Posts", posts_path
%li= link_to "Forums", forums_path
- if can? :create, Post
%li= link_to("Post something", new_post_path)
- if can? :create, Planting
%li= link_to("Plant something", new_planting_path)
%li.divider-vertical
- if member_signed_in?
%li.dropdown<

View File

@@ -50,6 +50,14 @@ describe 'member' do
@member.gardens.first.name.should eq "Garden"
end
it 'has many plantings through gardens' do
@member.save
@planting = FactoryGirl.create(:planting,
:garden => @member.gardens.first
)
@member.plantings.count.should eq 1
end
it "has many comments" do
@member.save
@comment1 = FactoryGirl.create(:comment, :author => @member)

View File

@@ -33,14 +33,6 @@ describe 'layouts/application.html.haml', :type => "view" do
rendered.should contain /member\d+/
end
it 'should have a "Post" link' do
rendered.should contain 'Post something'
end
it 'should have a plant something link' do
rendered.should contain 'Plant something'
end
it "should show member's name" do
assert_select("a[href=/members/#{@member.login_name}]", "Profile")
end