Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed contact requests and added some tests

  • Loading branch information...
commit 4ce633934aa790ed3911e19920cd63fc552bc444 1 parent 963922f
@rapind authored
View
1  .rspec
@@ -0,0 +1 @@
+--colour
View
5 app/controllers/contact_requests_controller.rb
@@ -1,11 +1,14 @@
class ContactRequestsController < ApplicationController
inherit_resources
respond_to :html
- actions :new, :create, :show
+ actions :new, :create
# Redirect to the edit path on update instead of show
def update
update!{ edit_admin_photographer_path }
end
+
+ def thanks
+ end
end
View
20 app/models/contact_request.rb
@@ -1,2 +1,22 @@
class ContactRequest < ActiveRecord::Base
+
+ # ****
+ # Validations
+ validates :email, :presence => true, :length => { :within => 5..100 }
+ validates :name, :length => { :within => 2..64, :allow_blank => true }
+ validates :subject, :presence => true, :length => { :within => 5..128 }
+
+ # ****
+ # Mass-assignment protection
+ attr_accessible :email, :name, :subject, :body
+
+ # ****
+ # Named scopes
+ scope :unread, where(:read => false)
+ scope :read, where(:read => true)
+
+ # ****
+ # Pagination
+ paginates_per 16
+
end
View
1  app/models/photographer.rb
@@ -13,6 +13,7 @@ class Photographer < ActiveRecord::Base
validates :blog_url, :length => { :within => 10..512, :allow_blank => true }
validates :facebook_url, :length => { :within => 10..255, :allow_blank => true }
validates :twitter_url, :length => { :within => 10..255, :allow_blank => true }
+ validates :disqus_short_name, :length => { :within => 2..64, :allow_blank => true }
validates :conversion_code, :length => { :within => 10..9000, :allow_blank => true }
# ****
View
0  app/views/contact_requests/new.html.haml
No changes.
View
2  app/views/contact_requests/thanks.html.haml
@@ -0,0 +1,2 @@
+%h1 Thanks
+%p Thank you for contacting me. I'll get back to you as soon as possible.
View
4 app/views/layouts/application.html.haml
@@ -15,9 +15,7 @@
%li= link_to('Kids', '#')
%li= link_to('Family', '#')
%li.divider-vertical
- %li= link_to('Pricing', '#')
- %li= link_to('About Me', '#')
- %li= link_to('Contact', '#')
+ %li{ :class => controller.controller_name == 'contact_requests' ? 'active' : '' }= link_to('Contact', new_contact_request_path)
- if photographer.blog_url
%li= link_to('Blog', photographer.blog_url)
.pull-right= link_to(photographer.name, root_path, :class => 'brand')
View
3  config/routes.rb
@@ -4,6 +4,9 @@
match 'timestamp' => 'home#timestamp' # used to keep passenger spooled up in prod
resources :galleries
+ resources :contact_requests, :only => [:new, :create] do
+ get :thanks, :on => :collection
+ end
devise_for :photographers
View
6 db/migrate/20120312231612_create_contact_requests.rb
@@ -2,14 +2,18 @@ class CreateContactRequests < ActiveRecord::Migration
def change
create_table :contact_requests do |t|
t.string :email, :null => false, :limit => 100
- t.string :subject, :null => false, :limit => 128
t.string :name, :limit => 64
+ t.string :subject, :null => false, :limit => 128
t.text :body
+ t.boolean :read, :null => false, :default => false
t.timestamps
end
# We don't want to start at 0.
execute "SELECT setval('contact_requests_id_seq', #{(rand(999) + 1000)});"
+
+ add_index :contact_requests, :read
+ add_index :contact_requests, :subject
end
end
View
3  spec/models/photographer_spec.rb
@@ -13,10 +13,9 @@
it { should validate_presence_of(:password) }
it { should validate_presence_of(:name) }
it { should ensure_length_of(:name).is_at_least(3).is_at_most(100) }
- it { should validate_presence_of(:description) }
it { should ensure_length_of(:description).is_at_least(10).is_at_most(8000) }
it { should ensure_length_of(:phone).is_at_least(7).is_at_most(20) }
- it { should ensure_length_of(:blog_url).is_at_least(10).is_at_most(255) }
+ it { should ensure_length_of(:blog_url).is_at_least(10).is_at_most(512) }
it { should ensure_length_of(:facebook_url).is_at_least(10).is_at_most(255) }
it { should ensure_length_of(:twitter_url).is_at_least(10).is_at_most(255) }
it { should ensure_length_of(:disqus_short_name).is_at_least(2).is_at_most(64) }
View
2  spec/routing/galleries_routing_spec.rb → spec/routing/admin/galleries_routing_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"
describe Admin::GalleriesController do
- describe "admin routing" do
+ describe "routing" do
it "routes to #index" do
get("/admin/galleries").should route_to("admin/galleries#index")
View
0  spec/routing/photographers_routing_spec.rb → ...uting/admin/photographers_routing_spec.rb
File renamed without changes
View
0  spec/routing/photos_routing_spec.rb → spec/routing/admin/photos_routing_spec.rb
File renamed without changes
View
19 spec/routing/contact_requests_routing_spec.rb
@@ -0,0 +1,19 @@
+require "spec_helper"
+
+describe ContactRequestsController do
+ describe "routing" do
+
+ it "routes to #new" do
+ get("/contact_requests/new").should route_to("contact_requests#new")
+ end
+
+ it "routes to #create" do
+ post("/contact_requests").should route_to("contact_requests#create")
+ end
+
+ it "routes to #thanks" do
+ get("/contact_requests/thanks").should route_to("contact_requests#thanks")
+ end
+
+ end
+end
View
2  spec/spec_helper.rb
@@ -18,4 +18,4 @@
config.after(:all) do
DatabaseCleaner.clean
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.