From 2a9c5e172a0a73acf5ea9555b15940cad6d84305 Mon Sep 17 00:00:00 2001 From: itkevin Date: Thu, 4 Apr 2013 23:00:37 +0200 Subject: [PATCH] User can now change password without having to provide an invitation code --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ app/models/user.rb | 2 +- spec/models/users_spec.rb | 18 ++++++++++-------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index a8bf2bb6..d8008d98 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,7 @@ end group :development, :test do gem 'rspec-rails' gem 'rspec' + gem 'shoulda-matchers' gem 'rr' gem 'webmock', :require => false gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock index ddaaef99..a290358b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,6 +43,8 @@ GEM rails (>= 3.1) bootstrap-sass (2.3.0.1) sass (~> 3.2) + bourne (1.4.0) + mocha (~> 0.13.2) builder (3.0.4) coderay (1.0.9) coffee-rails (3.2.2) @@ -119,8 +121,11 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + metaclass (0.0.1) method_source (0.8.1) mime-types (1.21) + mocha (0.13.3) + metaclass (~> 0.0.1) multi_json (1.6.1) multi_xml (0.5.3) multipart-post (1.2.0) @@ -204,6 +209,9 @@ GEM select2-rails (3.3.1) sass-rails (>= 3.2) thor (~> 0.14) + shoulda-matchers (1.5.6) + activesupport (>= 3.0.0) + bourne (~> 1.3) simple_oauth (0.1.9) slop (3.4.3) sprockets (2.2.2) @@ -273,6 +281,7 @@ DEPENDENCIES safe_yaml (= 0.8.6) sass-rails (~> 3.2.3) select2-rails + shoulda-matchers system_timer twitter twitter-stream (>= 0.1.16) diff --git a/app/models/user.rb b/app/models/user.rb index 433fc102..e83a7fca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,7 +19,7 @@ class User < ActiveRecord::Base validates_presence_of :username validates_uniqueness_of :username validates_format_of :username, :with => /\A[a-zA-Z0-9_-]{3,15}\Z/, :message => "can only contain letters, numbers, underscores, and dashes, and must be between 3 and 15 characters in length." - validates_inclusion_of :invitation_code, :in => INVITATION_CODES, :message => "is not valid" + validates_inclusion_of :invitation_code, :on => :create, :in => INVITATION_CODES, :message => "is not valid" has_many :events, :order => "events.created_at desc", :dependent => :delete_all, :inverse_of => :user has_many :agents, :order => "agents.created_at desc", :dependent => :destroy, :inverse_of => :user diff --git a/spec/models/users_spec.rb b/spec/models/users_spec.rb index 84c98ea9..ecaea966 100644 --- a/spec/models/users_spec.rb +++ b/spec/models/users_spec.rb @@ -3,14 +3,16 @@ require 'spec_helper' describe User do describe "validations" do describe "invitation_code" do - it "should be required and only be valid when set to one of the allowed values" do - users(:bob).should be_valid - users(:bob).invitation_code = "" - users(:bob).should_not be_valid - users(:bob).invitation_code = "something_fake" - users(:bob).should_not be_valid - users(:bob).invitation_code = User::INVITATION_CODES.first - users(:bob).should be_valid + it "only accepts valid invitation codes" do + User::INVITATION_CODES.each do |v| + should allow_value(v).for(:invitation_code) + end + end + + it "can reject invalid invitation codes" do + %w['foo', 'bar'].each do |v| + should_not allow_value(v).for(:invitation_code) + end end end end