Permalink
Browse files

Merge branch 'dev' of https://github.com/liufengyun/jobsworth into dev

  • Loading branch information...
2 parents b6b6714 + 57b8a1f commit 6373b238b7efa6e563dd250081e39edcd380eda8 @ari committed Jun 7, 2012
@@ -2,15 +2,16 @@ class Auth::PasswordsController < Devise::PasswordsController
layout "public"
def create
- email=EmailAddress.find_by_email(params[resource_name][:email])
+ email= EmailAddress.where("user_id IS NOT NULL").find_by_email(params[resource_name][:email])
+
if email
- user=User.find(email.user_id)
- self.resource = user.send_reset_password_instructions#(:email => email.email)
+ self.resource = email.user.send_reset_password_instructions#(:email => email.email)
else
flash[:error]="Invalid email!"
redirect_to new_user_password_path
return
end
+
if resource.errors.empty?
set_flash_message :success, :send_instructions
redirect_to new_session_path(resource_name)
@@ -3,6 +3,9 @@ class EmailAddress < ActiveRecord::Base
belongs_to :user
has_many :work_logs
has_and_belongs_to_many :abstract_tasks, :join_table=>'email_address_tasks', :association_foreign_key=>'task_id'
+
+ validates_presence_of :email
+ validates_uniqueness_of :email, :case_sensitive => false
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
def username_or_email
@@ -80,7 +80,7 @@ class WorkLog < ActiveRecord::Base
end
# reopens task if it's done
- if r.comment? && r.task.done?
+ if r.comment? && r.task.done? && (!r.event_log || r.event_log.event_type == EventLog::TASK_COMMENT)
r.task.update_attributes(
:completed_at => nil,
:status => Task.status_types.index("Open")
@@ -41,7 +41,7 @@
<label for="work_log_duration"><%=_ 'Time worked' %></label>
<div class="controls">
<%= text_field(:work_log, :duration, :value => worked_nice(@log.duration/60),
- :size => 10, :rel => 'tooltip', :title => _('1w 2d 3h 4m')) %>
+ :size => 10, :rel => 'tooltip', :title => _('1w 2d 3h 4m'), "data-placement" => "right") %>
</div>
</div>
</fieldset>
@@ -198,13 +198,6 @@
</div>
<div class="control-group">
- <label for="user_option_tracktime"><%=_ 'Track Time' %></label>
- <div class="controls">
- <%= check_box 'user', 'option_tracktime' %>
- </div>
- </div>
-
- <div class="control-group">
<%=label(:user, :access_level_id, _('Comment access level')) %>
<div class="controls">
<%=select :user, :access_level_id, AccessLevel.all.collect{|al| [al.name, al.id]}%>
@@ -35,7 +35,7 @@
<label for="work_log_duration"><%=_ 'Time worked' %></label>
<div class="controls">
<%= text_field(:work_log, :duration, :value => worked_nice(@log.duration/60),
- :size => 10, :rel => 'tooltip', :title => _('1w 2d 3h 4m')) %>
+ :size => 10, :rel => 'tooltip', :title => _('1w 2d 3h 4m'), "data-placement" => "right") %>
</div>
</div>
<% end %>
View
@@ -55,12 +55,16 @@ def self.paragraphs(paragraph_count = 3)
email { Sham.email }
end
+EmailAddress.blueprint do
+ email { Sham.email.gsub("@", "-#{rand(36**8).to_s(36)}@") }
+end
+
User.blueprint do
company
customer { company.internal_customer }
name
password
- email
+ email { Sham.email.gsub("@", "-#{rand(36**8).to_s(36)}@") }
time_zone "Australia/Sydney"
date_format { "%d/%m/%Y" }
time_format { "%H:%M" }
@@ -361,6 +361,23 @@ class << file
end
end
end
+ context "reopen closed task on commenting" do
+ setup do
+ @parameters.merge!(:comment => 'Just a comment')
+ end
+
+ should "not reopen task when comment on closing" do
+ @parameters[:task][:status] = 1
+ post(:update, @parameters)
+ assert_equal @task.reload.status, 1
+ end
+
+ should "reopen task when comment on closed task" do
+ @task.update_attributes(:status => 1)
+ post(:update, @parameters)
+ assert_equal @task.reload.status, Task.status_types.index("Open")
+ end
+ end
context "without comment," do
setup do
@parameters.merge!( :comment => nil)
@@ -0,0 +1,23 @@
+require 'test_helper'
+
+class ResetPasswordTest < ActionController::IntegrationTest
+ should "an email in email_addresses table without user_id be invalid" do
+ email = EmailAddress.make(:user_id => nil)
+ visit "/users/password/new"
+ fill_in "user_email", :with => email.email
+ click_button "Send me reset email"
+ assert page.has_content?("Invalid email!")
+ assert current_path == "/users/password/new"
+ end
+
+ should "an email in email_addresses table with user_id be able to reset" do
+ user = User.make
+ email = EmailAddress.make(:user => user)
+
+ visit "/users/password/new"
+ fill_in "user_email", :with => email.email
+ click_button "Send me reset email"
+
+ assert current_path == "/users/sign_in"
+ end
+end
@@ -1,9 +1,26 @@
require "test_helper"
class EmailAddressTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ test "invalid email format should fail" do
+ assert_raise(ActiveRecord::RecordInvalid) { EmailAddress.create!(:email => "invalid email address") }
+ end
+
+ test "duplicate email should fail" do
+ email = EmailAddress.make
+ assert_raise(ActiveRecord::RecordInvalid) { EmailAddress.create!(:email => email.email) }
+ end
+
+ test "email must be present" do
+ assert_raise(ActiveRecord::RecordInvalid) { EmailAddress.create!(:email => nil) }
+ end
+
+ test "email without user_id is OK" do
+ assert_nothing_raised { EmailAddress.create!(:email => Faker::Internet.email) }
+ end
+
+ test "normal email can be created" do
+ user = User.make
+ assert_nothing_raised { EmailAddress.create!(:email => Faker::Internet.email, :user => user) }
end
end
@@ -21,16 +21,17 @@ def setup
end
should "return new User object if work log doesn't have user" do
+ ed = EmailAddress.make
log = WorkLog.make(
:started_at => Time.now,
- :email_address => EmailAddress.create(:email => "unknownuser@jobsworth.com"),
+ :email_address => ed,
:user => nil,
:task => Task.make
)
user = log.user
assert user.new_record?
- assert_equal 'Unknown User (unknownuser@jobsworth.com)', user.name
+ assert_equal "Unknown User (#{ed.email})", user.name
assert_equal log.email_address.email, user.email
end

0 comments on commit 6373b23

Please sign in to comment.