Permalink
Browse files

adding testimonials

  • Loading branch information...
1 parent abeaa62 commit 8b3073008e7544621ce5e51adde07cbade19dd01 @saturnflyer committed Apr 29, 2009
@@ -3,6 +3,7 @@ class Client < ActiveRecord::Base
has_many :client_texts, :dependent => :destroy
has_many :projects, :dependent => :destroy
+ has_many :testimonials, :through => :client_testimonials, :dependent => :destroy
belongs_to :created_by, :class_name => 'User'
belongs_to :updated_by, :class_name => 'User'
@@ -0,0 +1,4 @@
+class ClientTestimonial < ActiveRecord::Base
+ has_one :client
+ has_one :testimonial
+end
@@ -3,6 +3,7 @@ class Project < ActiveRecord::Base
belongs_to :client
has_many :project_texts, :dependent => :destroy
+ has_many :testimonials, :through => :project_testimonials
belongs_to :created_by, :class_name => 'User'
belongs_to :updated_by, :class_name => 'User'
@@ -0,0 +1,4 @@
+class ProjectTestimonial < ActiveRecord::Base
+ has_one :project
+ has_one :testimonial
+end
@@ -0,0 +1,6 @@
+class Testimonial < ActiveRecord::Base
+ validates_presence_of :comment, :author
+
+ belongs_to :client_testimonial
+ belongs_to :project_testimonial
+end
@@ -0,0 +1,33 @@
+class CreateTestimonials < ActiveRecord::Migration
+ def self.up
+ create_table :testimonials do |t|
+ t.text :comment
+ t.string :author, :author_title
+ t.timestamps
+ end
+ add_index :testimonials, :author
+
+ create_table :project_testimonials do |t|
+ t.integer :project_id
+ t.integer :testimonial_id
+ end
+ add_index :project_testimonials, [:project_id, :testimonial_id], :unique => true
+
+ create_table :client_testimonials do |t|
+ t.integer :client_id
+ t.integer :testimonial_id
+ end
+ add_index :client_testimonials, [:client_id, :testimonial_id], :unique => true
+ end
+
+ def self.down
+ remove_index :client_testimonials, :column => [:client_id, :testimonial_id]
+ drop_table :client_testimonials
+
+ remove_index :project_testimonials, :column => [:project_id, :testimonial_id]
+ drop_table :project_testimonials
+
+ remove_index :testimonials, :author
+ drop_table :testimonials
+ end
+end
View
@@ -3,7 +3,7 @@ module PortfolioTags
class TagError < StandardError; end
- [:clients, :projects].each do |portfolio_model|
+ [:clients, :projects, :testimonials].each do |portfolio_model|
single_model = portfolio_model.to_s.singularize
tag "#{portfolio_model.to_s}" do |tag|
tag.expand
@@ -19,6 +19,9 @@ class TagError < StandardError; end
end
result
end
+ end
+ [:clients, :projects ].each do |portfolio_model|
+ single_model = portfolio_model.to_s.singularize
tag "#{portfolio_model.to_s}:each:name" do |tag|
tag.locals.send("#{single_model}").send(:name)
end
@@ -28,6 +31,16 @@ class TagError < StandardError; end
end
end
+ tag "testimonials:each:author" do |tag|
+ tag.locals.testimonial.author
+ end
+ tag "testimonials:each:author_title" do |tag|
+ tag.locals.testimonial.author_title
+ end
+ tag "testimonials:each:comment" do |tag|
+ tag.locals.testimonial.comment
+ end
+
def collection_find_options(tag, model)
attr = tag.attr.symbolize_keys
@@ -4,7 +4,7 @@
#Delete this example and add some real ones
it "should use ProjectsController" do
- controller.should be_an_instance_of(ProjectsController)
+ controller.should be_an_instance_of(Admin::ProjectsController)
end
end
@@ -1,19 +1,24 @@
class PortfolioDataset < Dataset::Base
- uses :users
+ uses :pages, :users
def load
create_client 'Saturn Flyer', 'designers and developers'
create_client 'Ignite Social Media', 'original' do
+ create_testimonial "They're work is incredible!", 'Gene Smith'
create_project 'ignite website', 'moving to Radiant'
end
create_client 'Kratos Defense', 'strength to success' do
- create_project 'iris', 'tracking users and deployments'
+ create_project 'iris', 'tracking users and deployments' do
+ create_testimonial 'We use IRIS more and more every day.', 'Vikram Khemani'
+ end
end
create_client 'Smithsonian', 'increase & diffusion of knowledge' do
create_project 'invertebrates', 'updating website'
end
create_client 'Bright Yellow Jacket', 'stand apart' do
- create_project 'byj site', 'developing website'
+ create_project 'byj site', 'developing website' do
+ create_testimonial 'We are very happy with this project', 'Stephen Oster', 'Founding Partner'
+ end
end
end
@@ -33,5 +38,18 @@ def create_project(name, text = nil)
unless text.blank?
create_record :project_text, :name => 'description', :content => text, :project_id => project_id(name.symbolize)
end
+ if block_given?
+ @project_id = project_id(name.symbolize)
+ yield
+ end
+ end
+
+ def create_testimonial(comment, author, author_title = nil)
+ create_record :testimonial, author.symbolize, :author => author, :comment => comment, :author_title => author_title
+ if !@project_id.blank?
+ create_record :project_testimonial, :testimonial_id => testimonial_id(author.symbolize), :project_id => @project_id
+ elsif !@client_id.blank?
+ create_record :client_testimonial, :testimonial_id => testimonial_id(author.symbolize), :client_id => @client_id
+ end
end
end
@@ -6,6 +6,7 @@
end
it "should have at least 1 client text" do
+ @client.save!
@client.should have_at_least(1).client_texts
end
end
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Page do
- dataset :pages, :portfolio
+ dataset :portfolio
describe "clients" do
it "should expand it's contents" do
@@ -112,4 +112,64 @@
end
end
end
+
+ describe "testimonials" do
+ it "should expand it's contents" do
+ pages(:home).should render('<r:testimonials>text</r:testimonials>').as('text')
+ end
+ describe "each" do
+ it "should expand it's contents for each item" do
+ pages(:home).should render('<r:testimonials:each>text </r:testimonials:each>').as('text text text ')
+ end
+ describe "with limit" do
+ it "should limit the records" do
+ pages(:home).should render('<r:testimonials:each limit="3">text </r:testimonials:each>').as('text text text ')
+ end
+ it "should error with a non-numeric limit" do
+ pages(:home).should render('<r:testimonials:each limit="abc">text </r:testimonials:each>').with_error("`limit' attribute of `each' tag must be a positive number between 1 and 4 digits")
+ end
+ it "should offset the records" do
+ pages(:home).should render('<r:testimonials:each limit="2" offset="1"><r:author /> </r:testimonials:each>').as('Vikram Khemani Stephen Oster ')
+ end
+ it "should error with a non-numeric offset" do
+ pages(:home).should render('<r:testimonials:each limit="3" offset="abc">text </r:testimonials:each>').with_error("`offset' attribute of `each' tag must be a positive number between 1 and 4 digits")
+ end
+ end
+ describe "with ordering" do
+ it "should sort by the given by field" do
+ pages(:home).should render('<r:testimonials:each limit="3" by="author"><r:author /> </r:testimonials:each>').as('Gene Smith Stephen Oster Vikram Khemani ')
+ end
+ it "should default sort by created_at" do
+ pages(:home).should render('<r:testimonials:each limit="3"><r:author /> </r:testimonials:each>').as('Gene Smith Vikram Khemani Stephen Oster ')
+ end
+ it "should err with an invalid by field" do
+ pages(:home).should render('<r:testimonials:each by="aoeu"><r:author /> </r:testimonials:each>').with_error("`by' attribute of `each' tag must be set to a valid field name")
+ end
+ it "should order by the given order field" do
+ pages(:home).should render('<r:testimonials:each limit="3" by="author" order="desc"><r:author /> </r:testimonials:each>').as('Vikram Khemani Stephen Oster Gene Smith ')
+ end
+ it "should default order to ascending" do
+ pages(:home).should render('<r:testimonials:each limit="3" by="author"><r:author /> </r:testimonials:each>').as('Gene Smith Stephen Oster Vikram Khemani ')
+ end
+ it "should err with an invalid order attribute" do
+ pages(:home).should render('<r:testimonials:each order="123"><r:author /></r:testimonials:each>').with_error(%{`order' attribute of `each' tag must be set to either "asc" or "desc"})
+ end
+ end
+ describe "author" do
+ it "should display the author" do
+ pages(:home).should render('<r:testimonials:each><r:author /> </r:testimonials:each>').as('Gene Smith Vikram Khemani Stephen Oster ')
+ end
+ end
+ describe "author_title" do
+ it "should display the author_title" do
+ pages(:home).should render('<r:testimonials:each><r:author_title /> </r:testimonials:each>').as(' Founding Partner ')
+ end
+ end
+ describe "content" do
+ it "should display the project comment" do
+ pages(:home).should render('<r:testimonials:each limit="1"><r:comment /></r:testimonials:each>').as("They're work is incredible!")
+ end
+ end
+ end
+ end
end
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Testimonial do
+ dataset :portfolio
+ before(:each) do
+ @testimonial = testimonials(:vikram_khemani)
+ end
+
+ it "should be valid" do
+ @testimonial.should be_valid
+ end
+
+ it "should not be valid without an author" do
+ @testimonial.author = nil
+ @testimonial.should_not be_valid
+ end
+
+ it "should not be valid without a comment" do
+ @testimonial.comment = nil
+ @testimonial.should_not be_valid
+ end
+end

0 comments on commit 8b30730

Please sign in to comment.