Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ania committed Dec 2, 2010
1 parent 27ebd02 commit 372113d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def destroy
def calendar
if current_user.is_admin?
if params[:user_id]
@users = Employee.all(:active => true, :order => [:name.asc])
@users = Employee.active(:order => [:name.asc])
else
@projects = Project.all(:order => [:name.asc])
end
Expand Down
11 changes: 3 additions & 8 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ class Invoice
end

def validate_activities
unless new_activities.blank?
is_valid = new_activities.map(&:valid?)
if is_valid.all?
true
else
return [false, "Some of activities are invalid (#{new_activities.first.errors.first.first})."]
end
else
if new_activities.blank? || new_activities.all?(&:valid?)
true
else
[false, "Some of activities are invalid (#{new_activities.first.errors.first.first})."]
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class User
has n, :versions, :model => UserVersion, :child_key => :id
has n, :free_days

def self.active
all(:active => true)
def self.active(options = {})
all({ :active => true }.merge(options))
end

def self.with_activities
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/kickstart.rake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace :rubytime do
# hourly rates
Project.all.each do |project|
puts "creating hourly rates for #{project.name}"
if HourlyRates.empty?
unless HourlyRate.all.any? { |hr| hr.project == project }
HourlyRate.create(:operation_author => admin, :project => project, :role => developer, :currency => Currency.first, :takes_effect_at => DateTime.now, :value => 777)
HourlyRate.create(:operation_author => admin, :project => project, :role => pm, :currency => Currency.first, :takes_effect_at => DateTime.now, :value => 888)
HourlyRate.create(:operation_author => admin, :project => project, :role => tester, :currency => Currency.first, :takes_effect_at => DateTime.now, :value => 666)
Expand Down
1 change: 0 additions & 1 deletion public/javascripts/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ var Activities = {
var dateParams = "?year=" + date.attr('data-current-year') + "&month=" + date.attr('data-current-month');
location = location.replace("/" + currentId + "/", "/" + $(this).val() + "/");
var locationWithoutParams = location.replace(/\?.*/, '');
console.log(locationWithoutParams);
window.location = locationWithoutParams + dateParams;
});

Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/invoices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
}).status.should == 302
end
end

it "should not create invoice if some of activities are not valid" do
project = Project.generate :client => @client
activity = Activity.generate :project => project
project.activity_types << ActivityType.generate
project.save

block_should_not(change(Activity.not_invoiced, :count).by(-1)) do
as(:admin).dispatch_to(Invoices, :create, :invoice => {
:name => "Theee Invoice",
:client_id => @client.id,
:activity_id => [activity.id]
}).status.should == 200
end
end
end

describe "#destroy" do
Expand Down

0 comments on commit 372113d

Please sign in to comment.