Skip to content
Browse files

for Rails 3.0.7, conform to app generated by template

  • Loading branch information...
1 parent 3d6d216 commit e1e79432bed6bd6df0dd8956638eca0966a7b53a @fortuity fortuity committed
View
4 .gitignore
@@ -2,10 +2,10 @@
# Ignore these files when commiting to a git repository
#
# The original version of this file is found here:
-# https://github.com/fortuity/rails3-gitignore/raw/master/gitignore.txt
+# https://github.com/RailsApps/rails3-application-templates/raw/master/files/gitignore.txt
#
# Corrections? Improvements? Create a GitHub issue:
-# https://github.com/fortuity/rails3-gitignore/issues
+# http://github.com/RailsApps/rails3-application-templates/issues
#----------------------------------------------------------------------------
# bundler state
View
21 Gemfile
@@ -1,12 +1,13 @@
source 'http://rubygems.org'
gem 'rails', '3.0.7'
-gem "rspec-rails", ">= 2.5.0", :group => [:development, :test]
-gem "database_cleaner", ">= 0.6.7", :group => :test
-gem "mongoid-rspec", ">= 1.4.1", :group => :test
-gem "factory_girl_rails", ">= 1.1.beta1", :group => :test
-gem "cucumber-rails", ">= 0.4.1", :group => :test
-gem "capybara", ">= 0.4.1.2", :group => :test
-gem "launchy", ">= 0.4.0", :group => :test
-gem "bson_ext", ">= 1.3.0"
-gem "mongoid", ">= 2.0.1"
-gem "devise", ">= 1.3.3"
+gem "rake", "0.8.7"
+gem "rspec-rails", "2.5.0", :group => [:development, :test]
+gem "database_cleaner", "0.6.7", :group => :test
+gem "mongoid-rspec", "1.4.2", :group => :test
+gem "factory_girl_rails", "1.1.beta1", :group => :test
+gem "cucumber-rails", "0.4.1", :group => :test
+gem "capybara", "0.4.1.2", :group => :test
+gem "launchy", "0.4.0", :group => :test
+gem "bson_ext", "1.3.1"
+gem "mongoid", "2.0.2"
+gem "devise", "1.3.4"
View
50 Gemfile.lock
@@ -28,10 +28,10 @@ GEM
activemodel (= 3.0.7)
activesupport (= 3.0.7)
activesupport (3.0.7)
- arel (2.0.9)
+ arel (2.0.10)
bcrypt-ruby (2.1.4)
- bson (1.3.0)
- bson_ext (1.3.0)
+ bson (1.3.1)
+ bson_ext (1.3.1)
builder (2.1.2)
capybara (0.4.1.2)
celerity (>= 0.7.9)
@@ -43,13 +43,13 @@ GEM
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.3)
celerity (0.8.9)
- childprocess (0.1.8)
+ childprocess (0.1.9)
ffi (~> 1.0.6)
configuration (1.2.0)
- cucumber (0.10.2)
+ cucumber (0.10.3)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
- gherkin (>= 2.3.5)
+ gherkin (>= 2.3.8)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
cucumber-rails (0.4.1)
@@ -69,9 +69,8 @@ GEM
factory_girl_rails (1.1.beta1)
factory_girl (~> 2.0.0.beta)
rails (>= 3.0.0)
- ffi (1.0.7)
- rake (>= 0.8.7)
- gherkin (2.3.7)
+ ffi (1.0.9)
+ gherkin (2.3.9)
json (>= 1.4.6)
i18n (0.5.0)
json (1.5.1)
@@ -85,20 +84,19 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- mongo (1.3.0)
- bson (>= 1.3.0)
- mongoid (2.0.1)
+ mongo (1.3.1)
+ bson (>= 1.3.1)
+ mongoid (2.0.2)
activemodel (~> 3.0)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
- will_paginate (~> 3.0.pre)
mongoid-rspec (1.4.2)
mongoid (~> 2.0)
rspec (~> 2)
nokogiri (1.4.4)
- orm_adapter (0.0.4)
+ orm_adapter (0.0.5)
polyglot (0.3.1)
- rack (1.2.2)
+ rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
@@ -143,7 +141,6 @@ GEM
tzinfo (0.3.27)
warden (1.0.4)
rack (>= 1.0)
- will_paginate (3.0.pre2)
xpath (0.1.4)
nokogiri (~> 1.3)
@@ -151,14 +148,15 @@ PLATFORMS
ruby
DEPENDENCIES
- bson_ext (>= 1.3.0)
- capybara (>= 0.4.1.2)
- cucumber-rails (>= 0.4.1)
- database_cleaner (>= 0.6.7)
- devise (>= 1.3.3)
- factory_girl_rails (>= 1.1.beta1)
- launchy (>= 0.4.0)
- mongoid (>= 2.0.1)
- mongoid-rspec (>= 1.4.1)
+ bson_ext (= 1.3.1)
+ capybara (= 0.4.1.2)
+ cucumber-rails (= 0.4.1)
+ database_cleaner (= 0.6.7)
+ devise (= 1.3.4)
+ factory_girl_rails (= 1.1.beta1)
+ launchy (= 0.4.0)
+ mongoid (= 2.0.2)
+ mongoid-rspec (= 1.4.2)
rails (= 3.0.7)
- rspec-rails (>= 2.5.0)
+ rake (= 0.8.7)
+ rspec-rails (= 2.5.0)
View
4 app/views/devise/registrations/edit.html.erb
@@ -2,8 +2,8 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
- <p><%= f.label :name %><br />
- <%= f.text_field :name %></p>
+<p><%= f.label :name %><br />
+<%= f.text_field :name %></p>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
View
4 app/views/devise/registrations/new.html.erb
@@ -2,8 +2,8 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
- <p><%= f.label :name %><br />
- <%= f.text_field :name %></p>
+<p><%= f.label :name %><br />
+<%= f.text_field :name %></p>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
View
1 app/views/users/show.html.erb
@@ -1,3 +1,4 @@
<h1>Users#show</h1>
<p>Find me in app/views/users/show.html.erb</p>
<p>User: <%= @user.name %></p>
+<p>Email: <%= @user.email if @user.email %></p>
View
7 config/application.rb
@@ -13,6 +13,13 @@
module Rails3MongoidDevise
class Application < Rails::Application
+
+ # don't generate RSpec tests for views and helpers
+ config.generators do |g|
+ g.view_specs false
+ g.helper_specs false
+ end
+
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
View
23 config/mongoid.yml
@@ -1,18 +1,10 @@
-defaults: &defaults
- host: localhost
- # slaves:
- # - host: slave1.local
- # port: 27018
- # - host: slave2.local
- # port: 27019
-
development:
- <<: *defaults
- database: rails3_mongoid_devise_development
+ host: localhost
+ database: testapp_development
test:
- <<: *defaults
- database: rails3_mongoid_devise_test
+ host: localhost
+ database: testapp_test
# set these environment variables on your prod server
production:
@@ -20,4 +12,9 @@ production:
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
- database: <%= ENV['MONGOID_DATABASE'] %>
+ database: <%= ENV['MONGOID_DATABASE'] %>
+ # slaves:
+ # - host: slave1.local
+ # port: 27018
+ # - host: slave2.local
+ # port: 27019
View
2 features/step_definitions/user_steps.rb
@@ -1,5 +1,5 @@
Given /^no user exists with an email of "(.*)"$/ do |email|
- assert_nil User.find(:first, :conditions => { :email => email })
+ User.find(:first, :conditions => { :email => email }).should be_nil
end
Given /^I am a user named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |name, email, password|
View
0 public/javascripts/.gitkeep
No changes.
View
6 public/javascripts/jquery.js
3 additions, 3 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
512 public/javascripts/rails.js
@@ -1,7 +1,7 @@
/**
* Unobtrusive scripting adapter for jQuery
*
- * Requires jQuery 1.4.3 or later.
+ * Requires jQuery 1.4.4 or later.
* https://github.com/rails/jquery-ujs
* Uploading file using rails.js
@@ -44,248 +44,272 @@
*/
(function($) {
-
- // Shorthand to make it a little easier to call public rails functions from within rails.js
- var rails;
-
- $.rails = rails = {
-
- // Link elements bound by jquery-ujs
- linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]',
-
- // Form elements bound by jquery-ujs
- formSubmitSelector: 'form',
-
- // Form input elements bound by jquery-ujs
- formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
-
- // Form input elements disabled during form submission
- disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
-
- // Form input elements re-enabled after form submission
- enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
-
- // Form required input elements
- requiredInputSelector: 'input[name][required],textarea[name][required]',
-
- // Form file input elements
- fileInputSelector: 'input:file',
-
- // Make sure that every Ajax request sends the CSRF token
- CSRFProtection: function(xhr) {
- var token = $('meta[name="csrf-token"]').attr('content');
- if (token) xhr.setRequestHeader('X-CSRF-Token', token);
- },
-
- // Triggers an event on an element and returns false if the event result is false
- fire: function(obj, name, data) {
- var event = $.Event(name);
- obj.trigger(event, data);
- return event.result !== false;
- },
-
- // Submits "remote" forms and links with ajax
- handleRemote: function(element) {
- var method, url, data,
- dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
-
- if (rails.fire(element, 'ajax:before')) {
-
- if (element.is('form')) {
- method = element.attr('method');
- url = element.attr('action');
- data = element.serializeArray();
- // memoized value from clicked submit button
- var button = element.data('ujs:submit-button');
- if (button) {
- data.push(button);
- element.data('ujs:submit-button', null);
- }
- } else {
- method = element.data('method');
- url = element.attr('href');
- data = null;
- }
-
- $.ajax({
- url: url, type: method || 'GET', data: data, dataType: dataType,
- // stopping the "ajax:beforeSend" event will cancel the ajax request
- beforeSend: function(xhr, settings) {
- if (settings.dataType === undefined) {
- xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
- }
- return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
- },
- success: function(data, status, xhr) {
- element.trigger('ajax:success', [data, status, xhr]);
- },
- complete: function(xhr, status) {
- element.trigger('ajax:complete', [xhr, status]);
- },
- error: function(xhr, status, error) {
- element.trigger('ajax:error', [xhr, status, error]);
- }
- });
- }
- },
-
- // Handles "data-method" on links such as:
- // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
- handleMethod: function(link) {
- var href = link.attr('href'),
- method = link.data('method'),
- csrf_token = $('meta[name=csrf-token]').attr('content'),
- csrf_param = $('meta[name=csrf-param]').attr('content'),
- form = $('<form method="post" action="' + href + '"></form>'),
- metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
-
- if (csrf_param !== undefined && csrf_token !== undefined) {
- metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
- }
-
- form.hide().append(metadata_input).appendTo('body');
- form.submit();
- },
-
- /* Disables form elements:
- - Caches element value in 'ujs:enable-with' data store
- - Replaces element text with value of 'data-disable-with' attribute
- - Adds disabled=disabled attribute
- */
- disableFormElements: function(form) {
- form.find(rails.disableSelector).each(function() {
- var element = $(this), method = element.is('button') ? 'html' : 'val';
- element.data('ujs:enable-with', element[method]());
- element[method](element.data('disable-with'));
- element.attr('disabled', 'disabled');
- });
- },
-
- /* Re-enables disabled form elements:
- - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
- - Removes disabled attribute
- */
- enableFormElements: function(form) {
- form.find(rails.enableSelector).each(function() {
- var element = $(this), method = element.is('button') ? 'html' : 'val';
- if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
- element.removeAttr('disabled');
- });
- },
-
- // If message provided in 'data-confirm' attribute, fires `confirm` event and returns result of confirm dialog.
- // Attaching a handler to the element's `confirm` event that returns false cancels the confirm dialog.
- allowAction: function(element) {
- var message = element.data('confirm');
- return !message || (rails.fire(element, 'confirm') && confirm(message));
- },
-
- // Helper function which checks for blank inputs in a form that match the specified CSS selector
- blankInputs: function(form, specifiedSelector, nonBlank) {
- var inputs = $(), input,
- selector = specifiedSelector || 'input,textarea';
- form.find(selector).each(function() {
- input = $(this);
- // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
- if (nonBlank ? input.val() : !input.val()) {
- inputs = inputs.add(input);
- }
- });
- return inputs.length ? inputs : false;
- },
-
- // Helper function which checks for non-blank inputs in a form that match the specified CSS selector
- nonBlankInputs: function(form, specifiedSelector) {
- return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
- },
-
- // Helper function, needed to provide consistent behavior in IE
- stopEverything: function(e) {
- e.stopImmediatePropagation();
- return false;
- },
-
- // find all the submit events directly bound to the form and
- // manually invoke them. If anyone returns false then stop the loop
- callFormSubmitBindings: function(form) {
- var events = form.data('events'), continuePropagation = true;
- if (events !== undefined && events['submit'] !== undefined) {
- $.each(events['submit'], function(i, obj){
- if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
- });
- }
- return continuePropagation;
- }
- };
-
- // ajaxPrefilter is a jQuery 1.5 feature
- if ('ajaxPrefilter' in $) {
- $.ajaxPrefilter(function(options, originalOptions, xhr){ rails.CSRFProtection(xhr); });
- } else {
- $(document).ajaxSend(function(e, xhr){ rails.CSRFProtection(xhr); });
- }
-
- $(rails.linkClickSelector).live('click.rails', function(e) {
- var link = $(this);
- if (!rails.allowAction(link)) return rails.stopEverything(e);
-
- if (link.data('remote') !== undefined) {
- rails.handleRemote(link);
- return false;
- } else if (link.data('method')) {
- rails.handleMethod(link);
- return false;
- }
- });
-
- $(rails.formSubmitSelector).live('submit.rails', function(e) {
- var form = $(this),
- remote = form.data('remote') !== undefined,
- blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
- nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
-
- if (!rails.allowAction(form)) return rails.stopEverything(e);
-
- // skip other logic when required values are missing or file upload is present
- if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
- return !remote;
- }
-
- if (remote) {
- if (nonBlankFileInputs) {
- return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
- }
-
- // If browser does not support submit bubbling, then this live-binding will be called before direct
- // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
- if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
-
- rails.handleRemote(form);
- return false;
- } else {
- // slight timeout so that the submit button gets properly serialized
- setTimeout(function(){ rails.disableFormElements(form); }, 13);
- }
- });
-
- $(rails.formInputClickSelector).live('click.rails', function(event) {
- var button = $(this);
-
- if (!rails.allowAction(button)) return rails.stopEverything(event);
-
- // register the pressed submit button
- var name = button.attr('name'),
- data = name ? {name:name, value:button.val()} : null;
-
- button.closest('form').data('ujs:submit-button', data);
- });
-
- $(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
- if (this == event.target) rails.disableFormElements($(this));
- });
-
- $(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
- if (this == event.target) rails.enableFormElements($(this));
- });
+ // Shorthand to make it a little easier to call public rails functions from within rails.js
+ var rails;
+
+ $.rails = rails = {
+ // Link elements bound by jquery-ujs
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]',
+
+ // Form elements bound by jquery-ujs
+ formSubmitSelector: 'form',
+
+ // Form input elements bound by jquery-ujs
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
+
+ // Form input elements disabled during form submission
+ disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
+
+ // Form input elements re-enabled after form submission
+ enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
+
+ // Form required input elements
+ requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
+
+ // Form file input elements
+ fileInputSelector: 'input:file',
+
+ // Make sure that every Ajax request sends the CSRF token
+ CSRFProtection: function(xhr) {
+ var token = $('meta[name="csrf-token"]').attr('content');
+ if (token) xhr.setRequestHeader('X-CSRF-Token', token);
+ },
+
+ // Triggers an event on an element and returns false if the event result is false
+ fire: function(obj, name, data) {
+ var event = $.Event(name);
+ obj.trigger(event, data);
+ return event.result !== false;
+ },
+
+ // Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
+ confirm: function(message) {
+ return confirm(message);
+ },
+
+ // Default ajax function, may be overridden with custom function in $.rails.ajax
+ ajax: function(options) {
+ return $.ajax(options);
+ },
+
+ // Submits "remote" forms and links with ajax
+ handleRemote: function(element) {
+ var method, url, data,
+ dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
+
+ if (rails.fire(element, 'ajax:before')) {
+
+ if (element.is('form')) {
+ method = element.attr('method');
+ url = element.attr('action');
+ data = element.serializeArray();
+ // memoized value from clicked submit button
+ var button = element.data('ujs:submit-button');
+ if (button) {
+ data.push(button);
+ element.data('ujs:submit-button', null);
+ }
+ } else {
+ method = element.data('method');
+ url = element.attr('href');
+ data = element.data('params') || null;
+ }
+
+ rails.ajax({
+ url: url, type: method || 'GET', data: data, dataType: dataType,
+ // stopping the "ajax:beforeSend" event will cancel the ajax request
+ beforeSend: function(xhr, settings) {
+ if (settings.dataType === undefined) {
+ xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
+ }
+ return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
+ },
+ success: function(data, status, xhr) {
+ element.trigger('ajax:success', [data, status, xhr]);
+ },
+ complete: function(xhr, status) {
+ element.trigger('ajax:complete', [xhr, status]);
+ },
+ error: function(xhr, status, error) {
+ element.trigger('ajax:error', [xhr, status, error]);
+ }
+ });
+ }
+ },
+
+ // Handles "data-method" on links such as:
+ // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
+ handleMethod: function(link) {
+ var href = link.attr('href'),
+ method = link.data('method'),
+ csrf_token = $('meta[name=csrf-token]').attr('content'),
+ csrf_param = $('meta[name=csrf-param]').attr('content'),
+ form = $('<form method="post" action="' + href + '"></form>'),
+ metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
+
+ if (csrf_param !== undefined && csrf_token !== undefined) {
+ metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
+ }
+
+ form.hide().append(metadata_input).appendTo('body');
+ form.submit();
+ },
+
+ /* Disables form elements:
+ - Caches element value in 'ujs:enable-with' data store
+ - Replaces element text with value of 'data-disable-with' attribute
+ - Adds disabled=disabled attribute
+ */
+ disableFormElements: function(form) {
+ form.find(rails.disableSelector).each(function() {
+ var element = $(this), method = element.is('button') ? 'html' : 'val';
+ element.data('ujs:enable-with', element[method]());
+ element[method](element.data('disable-with'));
+ element.attr('disabled', 'disabled');
+ });
+ },
+
+ /* Re-enables disabled form elements:
+ - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
+ - Removes disabled attribute
+ */
+ enableFormElements: function(form) {
+ form.find(rails.enableSelector).each(function() {
+ var element = $(this), method = element.is('button') ? 'html' : 'val';
+ if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
+ element.removeAttr('disabled');
+ });
+ },
+
+ /* For 'data-confirm' attribute:
+ - Fires `confirm` event
+ - Shows the confirmation dialog
+ - Fires the `confirm:complete` event
+
+ Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
+ Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
+ Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
+ return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
+ */
+ allowAction: function(element) {
+ var message = element.data('confirm'),
+ answer = false, callback;
+ if (!message) { return true; }
+
+ if (rails.fire(element, 'confirm')) {
+ answer = rails.confirm(message);
+ callback = rails.fire(element, 'confirm:complete', [answer]);
+ }
+ return answer && callback;
+ },
+
+ // Helper function which checks for blank inputs in a form that match the specified CSS selector
+ blankInputs: function(form, specifiedSelector, nonBlank) {
+ var inputs = $(), input,
+ selector = specifiedSelector || 'input,textarea';
+ form.find(selector).each(function() {
+ input = $(this);
+ // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
+ if (nonBlank ? input.val() : !input.val()) {
+ inputs = inputs.add(input);
+ }
+ });
+ return inputs.length ? inputs : false;
+ },
+
+ // Helper function which checks for non-blank inputs in a form that match the specified CSS selector
+ nonBlankInputs: function(form, specifiedSelector) {
+ return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
+ },
+
+ // Helper function, needed to provide consistent behavior in IE
+ stopEverything: function(e) {
+ $(e.target).trigger('ujs:everythingStopped');
+ e.stopImmediatePropagation();
+ return false;
+ },
+
+ // find all the submit events directly bound to the form and
+ // manually invoke them. If anyone returns false then stop the loop
+ callFormSubmitBindings: function(form) {
+ var events = form.data('events'), continuePropagation = true;
+ if (events !== undefined && events['submit'] !== undefined) {
+ $.each(events['submit'], function(i, obj){
+ if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
+ });
+ }
+ return continuePropagation;
+ }
+ };
+
+ // ajaxPrefilter is a jQuery 1.5 feature
+ if ('ajaxPrefilter' in $) {
+ $.ajaxPrefilter(function(options, originalOptions, xhr){ rails.CSRFProtection(xhr); });
+ } else {
+ $(document).ajaxSend(function(e, xhr){ rails.CSRFProtection(xhr); });
+ }
+
+ $(rails.linkClickSelector).live('click.rails', function(e) {
+ var link = $(this);
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
+
+ if (link.data('remote') !== undefined) {
+ rails.handleRemote(link);
+ return false;
+ } else if (link.data('method')) {
+ rails.handleMethod(link);
+ return false;
+ }
+ });
+
+ $(rails.formSubmitSelector).live('submit.rails', function(e) {
+ var form = $(this),
+ remote = form.data('remote') !== undefined,
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
+
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
+
+ // skip other logic when required values are missing or file upload is present
+ if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
+ return rails.stopEverything(e);
+ }
+
+ if (remote) {
+ if (nonBlankFileInputs) {
+ return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
+ }
+
+ // If browser does not support submit bubbling, then this live-binding will be called before direct
+ // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
+ if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
+
+ rails.handleRemote(form);
+ return false;
+ } else {
+ // slight timeout so that the submit button gets properly serialized
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
+ }
+ });
+
+ $(rails.formInputClickSelector).live('click.rails', function(event) {
+ var button = $(this);
+
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
+
+ // register the pressed submit button
+ var name = button.attr('name'),
+ data = name ? {name:name, value:button.val()} : null;
+
+ button.closest('form').data('ujs:submit-button', data);
+ });
+
+ $(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
+ if (this == event.target) rails.disableFormElements($(this));
+ });
+
+ $(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
+ if (this == event.target) rails.enableFormElements($(this));
+ });
})( jQuery );
View
11 spec/controllers/users_controller_spec.rb
@@ -3,15 +3,22 @@
describe UsersController do
before (:each) do
- @user = Factory.create(:user)
+ @user = Factory(:user)
sign_in @user
end
describe "GET 'show'" do
+
it "should be successful" do
- get 'show', :id => @user.id
+ get :show, :id => @user.id
response.should be_success
end
+
+ it "should find the right user" do
+ get :show, :id => @user.id
+ assigns(:user).should == @user
+ end
+
end
end
View
105 spec/models/user_spec.rb
@@ -1,8 +1,103 @@
require 'spec_helper'
describe User do
- it { should have_fields(:name, :email) }
- it { should validate_presence_of :name }
- it { should validate_uniqueness_of(:name) }
- it { should validate_uniqueness_of(:email) }
-end
+
+ 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 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

0 comments on commit e1e7943

Please sign in to comment.
Something went wrong with that request. Please try again.