From 9bd596e0e492f143bd941ff780a240f0258f6fc7 Mon Sep 17 00:00:00 2001 From: "Mike P. Kuhl" Date: Sat, 24 Sep 2011 16:54:02 +0200 Subject: [PATCH] introducing rspec; cleaning up the less stuff and try to use the "official" less gem which will work only with znix --- .gitignore | 1 + .rspec | 1 + Gemfile | 9 +- Gemfile.lock | 321 +++++++++--------- app/assets/javascripts/users.js.coffee | 3 + .../bootstrap/bootstrap.css.less.erb | 15 - .../stylesheets/bootstrap/bootstrap.less | 26 ++ .../stylesheets/bootstrap/bootstrap.notless | 26 -- app/assets/stylesheets/demo.css.scss | 3 - app/assets/stylesheets/home.css.scss | 3 - app/assets/stylesheets/page.css.scss | 3 - app/assets/stylesheets/users.css.less | 29 ++ app/controllers/users_controller.rb | 7 + app/helpers/users_helper.rb | 2 + app/views/users/show.html.erb | 18 + config/environments/development.rb | 2 +- config/environments/test.rb | 4 + config/routes.rb | 4 +- script/demo.rb | 5 + spec/controllers/home_controller_spec.rb | 6 + spec/controllers/users_controller_spec.rb | 9 + spec/helpers/users_helper_spec.rb | 15 + spec/models/user_spec.rb | 102 +++++- spec/spec_helper.rb | 27 ++ spec/support/devise.rb | 3 + 25 files changed, 425 insertions(+), 219 deletions(-) create mode 100644 .rspec create mode 100644 app/assets/javascripts/users.js.coffee delete mode 100644 app/assets/stylesheets/bootstrap/bootstrap.css.less.erb create mode 100644 app/assets/stylesheets/bootstrap/bootstrap.less delete mode 100644 app/assets/stylesheets/bootstrap/bootstrap.notless delete mode 100644 app/assets/stylesheets/demo.css.scss delete mode 100644 app/assets/stylesheets/home.css.scss delete mode 100644 app/assets/stylesheets/page.css.scss create mode 100644 app/assets/stylesheets/users.css.less create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/views/users/show.html.erb create mode 100644 script/demo.rb create mode 100644 spec/controllers/users_controller_spec.rb create mode 100644 spec/helpers/users_helper_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/devise.rb diff --git a/.gitignore b/.gitignore index c144064..2fedcfc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ log/*.log tmp/ .sass-cache/ .idea/ +vendor/plugins/Rename/ \ No newline at end of file diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..53607ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour diff --git a/Gemfile b/Gemfile index 91fd450..61527a5 100644 --- a/Gemfile +++ b/Gemfile @@ -11,15 +11,18 @@ gem 'rails', '3.1.0' group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" + gem "less" gem 'uglifier' end gem 'jquery-rails' -gem 'tilt', :git => 'git://github.com/thisduck/tilt.git' -gem 'less-js' -gem 'devise' +#gem 'tilt', :git => 'git://github.com/thisduck/tilt.git' +gem 'tilt' +#gem 'less-js' +# gem 'execjs' +gem 'devise' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 6f6b282..013147f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,161 +1,160 @@ -GIT - remote: git://github.com/thisduck/tilt.git - revision: a61592ebf52f48a5e94d1faadb227002013daccb - specs: - tilt (1.3.3) - -GEM - remote: http://rubygems.org/ - specs: - actionmailer (3.1.0) - actionpack (= 3.1.0) - mail (~> 2.3.0) - actionpack (3.1.0) - activemodel (= 3.1.0) - activesupport (= 3.1.0) - builder (~> 3.0.0) - erubis (~> 2.7.0) - i18n (~> 0.6) - rack (~> 1.3.2) - rack-cache (~> 1.0.3) - rack-mount (~> 0.8.2) - rack-test (~> 0.6.1) - sprockets (~> 2.0.0) - activemodel (3.1.0) - activesupport (= 3.1.0) - bcrypt-ruby (~> 3.0.0) - builder (~> 3.0.0) - i18n (~> 0.6) - activerecord (3.1.0) - activemodel (= 3.1.0) - activesupport (= 3.1.0) - arel (~> 2.2.1) - tzinfo (~> 0.3.29) - activeresource (3.1.0) - activemodel (= 3.1.0) - activesupport (= 3.1.0) - activesupport (3.1.0) - multi_json (~> 1.0) - ansi (1.3.0) - arel (2.2.1) - bcrypt-ruby (3.0.0-x86-mingw32) - builder (3.0.0) - coffee-rails (3.1.0) - coffee-script (>= 2.2.0) - railties (~> 3.1.0.rc1) - coffee-script (2.2.0) - coffee-script-source - execjs - coffee-script-source (1.1.2) - devise (1.4.4) - bcrypt-ruby (~> 3.0) - orm_adapter (~> 0.0.3) - warden (~> 1.0.3) - diff-lcs (1.1.3) - erubis (2.7.0) - execjs (1.2.4) - multi_json (~> 1.0) - factory_girl (2.1.0) - factory_girl_rails (1.2.0) - factory_girl (~> 2.1.0) - railties (>= 3.0.0) - faker (1.0.0) - i18n (~> 0.4) - hike (1.2.1) - i18n (0.6.0) - jquery-rails (1.0.13) - railties (~> 3.0) - thor (~> 0.14) - less-js (0.1.1) - execjs - less-js-source - less-js-source (1.1.3) - mail (2.3.0) - i18n (>= 0.4.0) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.16) - multi_json (1.0.3) - orm_adapter (0.0.5) - pg (0.11.0-x86-mingw32) - polyglot (0.3.2) - rack (1.3.2) - rack-cache (1.0.3) - rack (>= 0.4) - rack-mount (0.8.3) - rack (>= 1.0.0) - rack-ssl (1.3.2) - rack - rack-test (0.6.1) - rack (>= 1.0) - rails (3.1.0) - actionmailer (= 3.1.0) - actionpack (= 3.1.0) - activerecord (= 3.1.0) - activeresource (= 3.1.0) - activesupport (= 3.1.0) - bundler (~> 1.0) - railties (= 3.1.0) - railties (3.1.0) - actionpack (= 3.1.0) - activesupport (= 3.1.0) - rack-ssl (~> 1.3.2) - rake (>= 0.8.7) - rdoc (~> 3.4) - thor (~> 0.14.6) - rake (0.9.2) - rdoc (3.9.4) - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.4) - rspec-expectations (2.6.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) - rspec-rails (2.6.1) - actionpack (~> 3.0) - activesupport (~> 3.0) - railties (~> 3.0) - rspec (~> 2.6.0) - sass (3.1.7) - sass-rails (3.1.0) - actionpack (~> 3.1.0) - railties (~> 3.1.0) - sass (>= 3.1.4) - sprockets (2.0.0) - hike (~> 1.2) - rack (~> 1.0) - tilt (!= 1.3.0, ~> 1.1) - sqlite3 (1.3.4-x86-mingw32) - thor (0.14.6) - treetop (1.4.10) - polyglot - polyglot (>= 0.3.1) - turn (0.8.2) - ansi (>= 1.2.2) - tzinfo (0.3.29) - uglifier (1.0.3) - execjs (>= 0.3.0) - multi_json (>= 1.0.2) - warden (1.0.5) - rack (>= 1.0) - -PLATFORMS - x86-mingw32 - -DEPENDENCIES - coffee-rails (~> 3.1.0) - devise - factory_girl_rails - faker - jquery-rails - less-js - pg - rails (= 3.1.0) - rspec-rails (= 2.6.1) - sass-rails (~> 3.1.0) - sqlite3 - tilt! - turn - uglifier +GEM + remote: http://rubygems.org/ + specs: + actionmailer (3.1.0) + actionpack (= 3.1.0) + mail (~> 2.3.0) + actionpack (3.1.0) + activemodel (= 3.1.0) + activesupport (= 3.1.0) + builder (~> 3.0.0) + erubis (~> 2.7.0) + i18n (~> 0.6) + rack (~> 1.3.2) + rack-cache (~> 1.0.3) + rack-mount (~> 0.8.2) + rack-test (~> 0.6.1) + sprockets (~> 2.0.0) + activemodel (3.1.0) + activesupport (= 3.1.0) + bcrypt-ruby (~> 3.0.0) + builder (~> 3.0.0) + i18n (~> 0.6) + activerecord (3.1.0) + activemodel (= 3.1.0) + activesupport (= 3.1.0) + arel (~> 2.2.1) + tzinfo (~> 0.3.29) + activeresource (3.1.0) + activemodel (= 3.1.0) + activesupport (= 3.1.0) + activesupport (3.1.0) + multi_json (~> 1.0) + ansi (1.3.0) + arel (2.2.1) + bcrypt-ruby (3.0.1) + builder (3.0.0) + coffee-rails (3.1.1) + coffee-script (>= 2.2.0) + railties (~> 3.1.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.1.2) + devise (1.4.7) + bcrypt-ruby (~> 3.0) + orm_adapter (~> 0.0.3) + warden (~> 1.0.3) + diff-lcs (1.1.3) + erubis (2.7.0) + execjs (1.2.8) + multi_json (~> 1.0) + factory_girl (2.1.2) + activesupport + factory_girl_rails (1.2.0) + factory_girl (~> 2.1.0) + railties (>= 3.0.0) + faker (1.0.0) + i18n (~> 0.4) + hike (1.2.1) + i18n (0.6.0) + jquery-rails (1.0.14) + railties (~> 3.0) + thor (~> 0.14) + less (2.0.7) + therubyracer (~> 0.9.2) + libv8 (3.3.10.2) + mail (2.3.0) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.16) + multi_json (1.0.3) + orm_adapter (0.0.5) + pg (0.11.0) + polyglot (0.3.2) + rack (1.3.3) + rack-cache (1.0.3) + rack (>= 0.4) + rack-mount (0.8.3) + rack (>= 1.0.0) + rack-ssl (1.3.2) + rack + rack-test (0.6.1) + rack (>= 1.0) + rails (3.1.0) + actionmailer (= 3.1.0) + actionpack (= 3.1.0) + activerecord (= 3.1.0) + activeresource (= 3.1.0) + activesupport (= 3.1.0) + bundler (~> 1.0) + railties (= 3.1.0) + railties (3.1.0) + actionpack (= 3.1.0) + activesupport (= 3.1.0) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (~> 0.14.6) + rake (0.9.2) + rdoc (3.9.4) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) + rspec-rails (2.6.1) + actionpack (~> 3.0) + activesupport (~> 3.0) + railties (~> 3.0) + rspec (~> 2.6.0) + sass (3.1.7) + sass-rails (3.1.2) + actionpack (~> 3.1.0) + railties (~> 3.1.0) + sass (>= 3.1.4) + sprockets (~> 2.0.0) + tilt (~> 1.3.2) + sprockets (2.0.0) + hike (~> 1.2) + rack (~> 1.0) + tilt (!= 1.3.0, ~> 1.1) + sqlite3 (1.3.4) + therubyracer (0.9.4) + libv8 (~> 3.3.10) + thor (0.14.6) + tilt (1.3.3) + treetop (1.4.10) + polyglot + polyglot (>= 0.3.1) + turn (0.8.2) + ansi (>= 1.2.2) + tzinfo (0.3.29) + uglifier (1.0.3) + execjs (>= 0.3.0) + multi_json (>= 1.0.2) + warden (1.0.5) + rack (>= 1.0) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 3.1.0) + devise + factory_girl_rails + faker + jquery-rails + less + pg + rails (= 3.1.0) + rspec-rails (= 2.6.1) + sass-rails (~> 3.1.0) + sqlite3 + tilt + turn + uglifier diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/bootstrap/bootstrap.css.less.erb b/app/assets/stylesheets/bootstrap/bootstrap.css.less.erb deleted file mode 100644 index 97b583e..0000000 --- a/app/assets/stylesheets/bootstrap/bootstrap.css.less.erb +++ /dev/null @@ -1,15 +0,0 @@ -/* CSS Reset */ -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/reset.less" %> - -/* Core */ -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/variables.less" %> -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/mixins.less" %> - -// Grid system and page structure -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/scaffolding.less" %> - -/* Styled patterns and elements */ -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/type.less" %> -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/forms.less" %> -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/tables.less" %> -<%= File.read "#{Rails.root}/app/assets/stylesheets/bootstrap/patterns.less" %> \ No newline at end of file diff --git a/app/assets/stylesheets/bootstrap/bootstrap.less b/app/assets/stylesheets/bootstrap/bootstrap.less new file mode 100644 index 0000000..339e3b7 --- /dev/null +++ b/app/assets/stylesheets/bootstrap/bootstrap.less @@ -0,0 +1,26 @@ +/*! + * Bootstrap @VERSION + * + * Copyright 2011 Twitter, Inc + * Licensed under the Apache License v2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Designed and built with all the love in the world @twitter by @mdo and @fat. + * Date: @DATE + */ + +// CSS Reset +@import "app/assets/stylesheets/bootstrap/reset.less"; + +// Core variables and mixins +@import "app/assets/stylesheets/bootstrap/variables.less"; // Modify this for custom colors, font-sizes, etc +@import "app/assets/stylesheets/bootstrap/mixins.less"; + +// Grid system and page structure +@import "app/assets/stylesheets/bootstrap/scaffolding.less"; + +// Styled patterns and elements +@import "app/assets/stylesheets/bootstrap/type.less"; +@import "app/assets/stylesheets/bootstrap/forms.less"; +@import "app/assets/stylesheets/bootstrap/tables.less"; +@import "app/assets/stylesheets/bootstrap/patterns.less"; \ No newline at end of file diff --git a/app/assets/stylesheets/bootstrap/bootstrap.notless b/app/assets/stylesheets/bootstrap/bootstrap.notless deleted file mode 100644 index c1e1c2e..0000000 --- a/app/assets/stylesheets/bootstrap/bootstrap.notless +++ /dev/null @@ -1,26 +0,0 @@ -/*! - * Bootstrap @VERSION - * - * Copyright 2011 Twitter, Inc - * Licensed under the Apache License v2.0 - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Designed and built with all the love in the world @twitter by @mdo and @fat. - * Date: @DATE - */ - -// CSS Reset -@import "reset.less"; - -// Core variables and mixins -@import "variables.less"; // Modify this for custom colors, font-sizes, etc -@import "mixins.less"; - -// Grid system and page structure -@import "scaffolding.less"; - -// Styled patterns and elements -@import "type.less"; -@import "forms.less"; -@import "tables.less"; -@import "patterns.less"; \ No newline at end of file diff --git a/app/assets/stylesheets/demo.css.scss b/app/assets/stylesheets/demo.css.scss deleted file mode 100644 index 6eb6342..0000000 --- a/app/assets/stylesheets/demo.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the demo controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/home.css.scss b/app/assets/stylesheets/home.css.scss deleted file mode 100644 index f0ddc68..0000000 --- a/app/assets/stylesheets/home.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the home controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/page.css.scss b/app/assets/stylesheets/page.css.scss deleted file mode 100644 index 080b530..0000000 --- a/app/assets/stylesheets/page.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the page controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.css.less b/app/assets/stylesheets/users.css.less new file mode 100644 index 0000000..3d8600d --- /dev/null +++ b/app/assets/stylesheets/users.css.less @@ -0,0 +1,29 @@ + + +//div.attrlist { +// margin-bottom: @baseline; +// padding-top: @baseline; +// +// .clearfix { +// margin-bottom: @baseline; +// .clearfix() +// } +// +// div.label { +// padding-top: 6px; +// font-size: @basefont; +// line-height: @baseline; +// float: left; +// width: 130px; +// text-align: right; +// color: @grayDark; +// } +// +// div.value { +// margin-left: 150px; +// } +// +// +//} + + diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..8f0845c --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,7 @@ +class UsersController < ApplicationController + def show + logger.info ("start fetching user id #{params[:id]}") + @user = User.find(params[:id]) + logger.info ("found user #{@user.name}") + end +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..d766bec --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,18 @@ +
+ +
+
+
+
+
Name:
<%= @user.name %>
+
+
+
EMail Address:
<%= @user.email %>
+
+
+ +
+
+
\ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 8edbb54..aecf74f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -7,7 +7,7 @@ config.cache_classes = false # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true + config.whiny_nils = false # Show full error reports and disable caching config.consider_all_requests_local = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 1f5936c..3766ba2 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -39,4 +39,8 @@ # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets config.assets.allow_debugging = true + + # needed for devise 'confirmable' + config.action_mailer.default_url_options = { :host => 'localhost:3000' } + end diff --git a/config/routes.rb b/config/routes.rb index 256c0cb..d05896a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Bootstrap::Application.routes.draw do devise_for :users + resources :users, :only => :show match 'home/:action' => 'home#:action', :as => :home @@ -12,8 +13,6 @@ root :to => 'home#index' - - # The priority is based upon order of creation: # first created -> highest priority. @@ -63,7 +62,6 @@ # You can have the root of your site routed with "root" # just remember to delete public/index.html. - root :to => 'home#home' # See how all your routes lay out with "rake routes" diff --git a/script/demo.rb b/script/demo.rb new file mode 100644 index 0000000..36fc5d9 --- /dev/null +++ b/script/demo.rb @@ -0,0 +1,5 @@ + +puts "hello 1" +puts "help 2" +puts "demo 3" + diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 9d48b6a..07004c9 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -1,5 +1,11 @@ require 'spec_helper' describe HomeController do + describe "GET 'index'" do + it "should be successful" do + get 'index' + response.should be_success + end + end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb new file mode 100644 index 0000000..6118b3f --- /dev/null +++ b/spec/controllers/users_controller_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe UsersController do + + def show + @user = User.find(params[:id]) + end + +end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb new file mode 100644 index 0000000..e65fff9 --- /dev/null +++ b/spec/helpers/users_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the UsersHelper. For example: +# +# describe UsersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe UsersHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1c62cb2..22a7da0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,105 @@ require 'spec_helper' describe User do - pending "add some examples to (or delete) #{__FILE__}" + before(:each) do + @attr = { + :name => "Example User", + :email => "user@example.com", + :password => "foobar", + :password_confirmation => "foobar" + } + end + + it "should create a new instance given a valid attribute" do + User.create!(@attr) + end + + it "should require a user name" do + User.create!(@attr) + no_name_user = User.new(@attr.merge(:name => "")) + no_name_user.should_not be_valid + end + + :name + + it "should require an email address" do + no_email_user = User.new(@attr.merge(:email => "")) + no_email_user.should_not be_valid + end + + it "should accept valid email addresses" do + addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp] + addresses.each do |address| + valid_email_user = User.new(@attr.merge(:email => address)) + valid_email_user.should be_valid + end + end + + it "should reject invalid email addresses" do + addresses = %w[user@foo,com user_at_foo.org example.user@foo.] + addresses.each do |address| + invalid_email_user = User.new(@attr.merge(:email => address)) + invalid_email_user.should_not be_valid + end + end + + it "should reject duplicate email addresses" do + User.create!(@attr) + user_with_duplicate_email = User.new(@attr) + user_with_duplicate_email.should_not be_valid + end + + it "should reject email addresses identical up to case" do + upcased_email = @attr[:email].upcase + User.create!(@attr.merge(:email => upcased_email)) + user_with_duplicate_email = User.new(@attr) + user_with_duplicate_email.should_not be_valid + end + + describe "passwords" do + before(:each) do + @user = User.new(@attr) + end + + it "should have a password attribute" do + @user.should respond_to(:password) + end + + it "should have a password confirmation attribute" do + @user.should respond_to(:password_confirmation) + end + end + + describe "password validations" do + it "should require a password" do + User.new(@attr.merge(:password => "", :password_confirmation => "")). + should_not be_valid + end + + it "should require a matching password confirmation" do + User.new(@attr.merge(:password_confirmation => "invalid")). + should_not be_valid + end + + it "should reject short passwords" do + short = "a" * 5 + hash = @attr.merge(:password => short, :password_confirmation => short) + User.new(hash).should_not be_valid + end + end + + describe "password encryption" do + before(:each) do + @user = User.create!(@attr) + end + + it "should have an encrypted password attribute" do + @user.should respond_to(:encrypted_password) + end + + it "should set the encrypted password attribute" do + @user.encrypted_password.should_not be_blank + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..9b8b02c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,27 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} + +RSpec.configure do |config| + # == Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + config.mock_with :rspec + + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true +end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 0000000..4e78097 --- /dev/null +++ b/spec/support/devise.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller +end \ No newline at end of file