Permalink
Browse files

specs

  • Loading branch information...
amatsuda committed May 13, 2012
1 parent 77d484e commit c313a0d89d7b2de62ab7c5af1e1a8914a1496b75
Showing with 105 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 .rspec
  3. +8 −0 Rakefile
  4. +4 −0 html5_validators.gemspec
  5. +47 −0 spec/fake_app.rb
  6. +25 −0 spec/requests/validation_spec.rb
  7. +17 −0 spec/spec_helper.rb
View
@@ -2,3 +2,5 @@
.bundle
Gemfile.lock
pkg/*
+tmp
+log
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format=d
View
@@ -1,2 +1,10 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+
+task :noop do; end
+task :default => :spec
+
+RSpec::Core::RakeTask.new(:spec => :noop)
View
@@ -18,4 +18,8 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ['lib']
+ s.add_development_dependency 'activerecord'
+ s.add_development_dependency 'rspec-rails'
+ s.add_development_dependency 'capybara'
+ s.add_development_dependency 'sqlite3'
end
View
@@ -0,0 +1,47 @@
+require 'active_record'
+require 'action_controller/railtie'
+
+# config
+ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
+
+app = Class.new(Rails::Application)
+app.config.secret_token = "You know I'm born to lose, and gambling's for fools, But that's the way I like it baby, I don't wanna live for ever, And don't forget the joker!"
+app.config.session_store :cookie_store, :key => '_myapp_session'
+app.config.active_support.deprecation = :log
+app.initialize!
+
+# routes
+app.routes.draw do
+ resources :people, :only => [:new, :create] do
+ collection do
+ get :new_without_html5_validation
+ end
+ end
+end
+
+# models
+class Person < ActiveRecord::Base
+end
+
+# controllers
+class ApplicationController < ActionController::Base; end
+class PeopleController < ApplicationController
+ def new
+ @person = Person.new
+ render :inline => <<-ERB
+<%= form_for @person do |f| %>
+<%= f.text_field :name %>
+<% end %>
+ERB
+ end
+end
+
+# helpers
+module ApplicationHelper; end
+
+#migrations
+class CreateAllTables < ActiveRecord::Migration
+ def self.up
+ create_table(:people) {|t| t.string :name; t.string :email; t.integer :age}
+ end
+end
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+feature 'person#new' do
+ context 'without validation' do
+ scenario 'new form' do
+ visit '/people/new'
+ page.should have_css('input#person_name')
+ page.should_not have_css('input#person_name[required=required]')
+ end
+ end
+
+ context 'with required validation' do
+ background do
+ Person.validates_presence_of :name
+ end
+ after do
+ Person._validators.clear
+ end
+ scenario 'new form' do
+ visit '/people/new'
+ page.should have_css('input#person_name')
+ page.should have_css('input#person_name[required=required]')
+ end
+ end
+end
View
@@ -0,0 +1,17 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+# load Rails first
+require 'rails'
+require 'html5_validators'
+# needs to load the app before loading rspec/rails => capybara
+require 'fake_app'
+require 'rspec/rails'
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+ config.before :all do
+ CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'people'
+ end
+end

0 comments on commit c313a0d

Please sign in to comment.