Skip to content

Instantly share code, notes, and snippets.

@madpilot
Created February 22, 2010 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madpilot/310930 to your computer and use it in GitHub Desktop.
Save madpilot/310930 to your computer and use it in GitHub Desktop.
Some sample test setup files
require 'machinist/active_record'
require 'sham'
require 'faker'
Sham.define do
title { Faker::Lorem.words(2).join(' ') }
permalink { Faker::Lorem.words(2).join('-') }
status(:unique => false) do
case(rand(3))
when 0:
'draft'
when 1:
'published'
when 2:
'archived'
end
end
description { Faker::Lorem.words(12).join(' ') }
keywords { Faker::Lorem.words(8).join(',') }
copy { Faker::Lorem.words(1024).join(' ') }
path { Faker::Lorem.words(2).join('/') }
link { Faker::Internet.domain_name }
integer { rand(100) }
login { Faker::Name.first_name.underscore }
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
email { Faker::Internet.email }
password { (0..6).inject('') { |t, c| t += (rand(?z - ?a) + ?a).floor.chr } }
end
gem install shoulda
gem intstall mocha
gem install faker
gem install machinist
(All on gemcutter)
require 'test_helper'
class MenuItemTest < ActiveSupport::TestCase
context '' do
setup do
@menu_item = MenuItem.make
I18n.locale = 'en'
end
subject { @menu_item }
should_validate_presence_of :title
should_validate_presence_of :permalink
should_validate_uniqueness_of :permalink
should_belong_to :subject
context 'locale' do
setup do
@it_menu_item = MenuItem.make(:locale => 'it')
@cn_menu_item = MenuItem.make(:locale => 'cn')
end
should "set the locale to the default if it isn't already set" do
@menu_item = MenuItem.make(:locale => nil)
@menu_item.valid?
assert_equal 'en', @menu_item.locale
end
context 'localized' do
should 'return all the menu items in the supplied locale' do
assert_equal [ @menu_item ], MenuItem.localized('en')
assert_equal [ @it_menu_item ], MenuItem.localized('it')
assert_equal [ @cn_menu_item ], MenuItem.localized('cn')
end
end
context 'localized_root' do
should 'return to root of the locale' do
assert_equal @menu_item, MenuItem.localized_root('en')
assert_equal @it_menu_item, MenuItem.localized_root('it')
assert_equal @cn_menu_item, MenuItem.localized_root('cn')
end
end
end
end
end
require 'redgreen'
require 'test/unit'
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'blueprints'
require 'mocha'
class ActiveSupport::TestCase
# Add more helper methods to be used by all tests here...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment