mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Added first integration test
This test tests the following Draper features: 1) finders 2) decorates 3) using a decorated method It also is the first test that verifies that the whole Cucumber setup actually works properly.
This commit is contained in:
parent
90a4859085
commit
6b5b0a77ee
18 changed files with 135 additions and 56 deletions
6
features/posts.feature
Normal file
6
features/posts.feature
Normal file
|
@ -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
|
11
features/step_definitions/post_steps.rb
Normal file
11
features/step_definitions/post_steps.rb
Normal file
|
@ -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
|
2
spec/dummy/app/assets/javascripts/posts.js
Normal file
2
spec/dummy/app/assets/javascripts/posts.js
Normal file
|
@ -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.
|
4
spec/dummy/app/assets/stylesheets/posts.css
Normal file
4
spec/dummy/app/assets/stylesheets/posts.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
5
spec/dummy/app/controllers/posts_controller.rb
Normal file
5
spec/dummy/app/controllers/posts_controller.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class PostsController < ApplicationController
|
||||
def show
|
||||
@post = PostDecorator.find(params[:id])
|
||||
end
|
||||
end
|
40
spec/dummy/app/decorators/post_decorator.rb
Normal file
40
spec/dummy/app/decorators/post_decorator.rb
Normal file
|
@ -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
|
2
spec/dummy/app/helpers/posts_helper.rb
Normal file
2
spec/dummy/app/helpers/posts_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module PostsHelper
|
||||
end
|
3
spec/dummy/app/models/post.rb
Normal file
3
spec/dummy/app/models/post.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Post < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
end
|
1
spec/dummy/app/views/posts/show.html.erb
Normal file
1
spec/dummy/app/views/posts/show.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
Posted: <%= @post.posted_date %>
|
|
@ -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
|
||||
|
|
BIN
spec/dummy/db/development.sqlite3
Normal file
BIN
spec/dummy/db/development.sqlite3
Normal file
Binary file not shown.
8
spec/dummy/db/migrate/20121019115657_create_posts.rb
Normal file
8
spec/dummy/db/migrate/20121019115657_create_posts.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class CreatePosts < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :posts do |t|
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
21
spec/dummy/db/schema.rb
Normal file
21
spec/dummy/db/schema.rb
Normal file
|
@ -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
|
BIN
spec/dummy/db/test.sqlite3
Normal file
BIN
spec/dummy/db/test.sqlite3
Normal file
Binary file not shown.
11
spec/dummy/test/fixtures/posts.yml
vendored
Normal file
11
spec/dummy/test/fixtures/posts.yml
vendored
Normal file
|
@ -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
|
9
spec/dummy/test/functional/posts_controller_test.rb
Normal file
9
spec/dummy/test/functional/posts_controller_test.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PostsControllerTest < ActionController::TestCase
|
||||
test "should get show" do
|
||||
get :show
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
4
spec/dummy/test/unit/helpers/posts_helper_test.rb
Normal file
4
spec/dummy/test/unit/helpers/posts_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PostsHelperTest < ActionView::TestCase
|
||||
end
|
7
spec/dummy/test/unit/post_test.rb
Normal file
7
spec/dummy/test/unit/post_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Add table
Reference in a new issue