diff --git a/features/posts.feature b/features/posts.feature new file mode 100644 index 0000000..4ce949c --- /dev/null +++ b/features/posts.feature @@ -0,0 +1,6 @@ +Feature: Blog posts + + Scenario: A post exists with the correct time + Given a blog post exists that was posted today + When I visit the page for that post + Then I should see that it was posted today diff --git a/features/step_definitions/post_steps.rb b/features/step_definitions/post_steps.rb new file mode 100644 index 0000000..9b1150d --- /dev/null +++ b/features/step_definitions/post_steps.rb @@ -0,0 +1,11 @@ +Given /^a blog post exists that was posted today$/ do + @post = Post.create +end + +When /^I visit the page for that post$/ do + visit post_path(@post) +end + +Then /^I should see that it was posted today$/ do + page.should have_content("Posted: Today") +end diff --git a/spec/dummy/app/assets/javascripts/posts.js b/spec/dummy/app/assets/javascripts/posts.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/spec/dummy/app/assets/javascripts/posts.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/spec/dummy/app/assets/stylesheets/posts.css b/spec/dummy/app/assets/stylesheets/posts.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/posts.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/spec/dummy/app/controllers/posts_controller.rb b/spec/dummy/app/controllers/posts_controller.rb new file mode 100644 index 0000000..88e34e1 --- /dev/null +++ b/spec/dummy/app/controllers/posts_controller.rb @@ -0,0 +1,5 @@ +class PostsController < ApplicationController + def show + @post = PostDecorator.find(params[:id]) + end +end diff --git a/spec/dummy/app/decorators/post_decorator.rb b/spec/dummy/app/decorators/post_decorator.rb new file mode 100644 index 0000000..1879e12 --- /dev/null +++ b/spec/dummy/app/decorators/post_decorator.rb @@ -0,0 +1,40 @@ +class PostDecorator < Draper::Base + decorates :post + + def posted_date + if created_at.to_date == Date.today + "Today" + else + "Not Today" + end + end + + # Accessing Helpers + # You can access any helper via a proxy + # + # Normal Usage: helpers.number_to_currency(2) + # Abbreviated : h.number_to_currency(2) + # + # Or, optionally enable "lazy helpers" by including this module: + # include Draper::LazyHelpers + # Then use the helpers with no proxy: + # number_to_currency(2) + + # Defining an Interface + # Control access to the wrapped subject's methods using one of the following: + # + # To allow only the listed methods (whitelist): + # allows :method1, :method2 + # + # To allow everything except the listed methods (blacklist): + # denies :method1, :method2 + + # Presentation Methods + # Define your own instance methods, even overriding accessors + # generated by ActiveRecord: + # + # def created_at + # h.content_tag :span, attributes["created_at"].strftime("%a %m/%d/%y"), + # :class => 'timestamp' + # end +end diff --git a/spec/dummy/app/helpers/posts_helper.rb b/spec/dummy/app/helpers/posts_helper.rb new file mode 100644 index 0000000..a7b8cec --- /dev/null +++ b/spec/dummy/app/helpers/posts_helper.rb @@ -0,0 +1,2 @@ +module PostsHelper +end diff --git a/spec/dummy/app/models/post.rb b/spec/dummy/app/models/post.rb new file mode 100644 index 0000000..6cc74b1 --- /dev/null +++ b/spec/dummy/app/models/post.rb @@ -0,0 +1,3 @@ +class Post < ActiveRecord::Base + # attr_accessible :title, :body +end diff --git a/spec/dummy/app/views/posts/show.html.erb b/spec/dummy/app/views/posts/show.html.erb new file mode 100644 index 0000000..e0ba96a --- /dev/null +++ b/spec/dummy/app/views/posts/show.html.erb @@ -0,0 +1 @@ +Posted: <%= @post.posted_date %> diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index eb8579b..396e41e 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,58 +1,3 @@ Dummy::Application.routes.draw do - # The priority is based upon order of creation: - # first created -> highest priority. - - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => 'welcome#index' - - # See how all your routes lay out with "rake routes" - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id))(.:format)' + resources :posts, :only => [:show] end diff --git a/spec/dummy/db/development.sqlite3 b/spec/dummy/db/development.sqlite3 new file mode 100644 index 0000000..cab2e2a Binary files /dev/null and b/spec/dummy/db/development.sqlite3 differ diff --git a/spec/dummy/db/migrate/20121019115657_create_posts.rb b/spec/dummy/db/migrate/20121019115657_create_posts.rb new file mode 100644 index 0000000..30d7c04 --- /dev/null +++ b/spec/dummy/db/migrate/20121019115657_create_posts.rb @@ -0,0 +1,8 @@ +class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + + t.timestamps + end + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb new file mode 100644 index 0000000..fe5946e --- /dev/null +++ b/spec/dummy/db/schema.rb @@ -0,0 +1,21 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20121019115657) do + + create_table "posts", :force => true do |t| + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + +end diff --git a/spec/dummy/db/test.sqlite3 b/spec/dummy/db/test.sqlite3 new file mode 100644 index 0000000..7a6ffcf Binary files /dev/null and b/spec/dummy/db/test.sqlite3 differ diff --git a/spec/dummy/test/fixtures/posts.yml b/spec/dummy/test/fixtures/posts.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/spec/dummy/test/fixtures/posts.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/spec/dummy/test/functional/posts_controller_test.rb b/spec/dummy/test/functional/posts_controller_test.rb new file mode 100644 index 0000000..45ee301 --- /dev/null +++ b/spec/dummy/test/functional/posts_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + test "should get show" do + get :show + assert_response :success + end + +end diff --git a/spec/dummy/test/unit/helpers/posts_helper_test.rb b/spec/dummy/test/unit/helpers/posts_helper_test.rb new file mode 100644 index 0000000..48549c2 --- /dev/null +++ b/spec/dummy/test/unit/helpers/posts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class PostsHelperTest < ActionView::TestCase +end diff --git a/spec/dummy/test/unit/post_test.rb b/spec/dummy/test/unit/post_test.rb new file mode 100644 index 0000000..6d9d463 --- /dev/null +++ b/spec/dummy/test/unit/post_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end