Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/tasks/award_badge_once.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace :award_badge_once do
desc "TODO"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO? ;)

task award_organized_badge: :environment do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just organized_badge as award is already in namespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DMips @pg20 Let's have one rake file for award badges and add all tasks under one namespace for 'award badges'. Should we ?

@projects = Project.all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is weird - standard in ruby is 2 spaces

@edition = Edition.last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use Project.current_edition which will return all projects from well this edition so no need to declare @edition variable

@projects.each do |project|
is_organised_flag = true
@edition.weeks.each do |week|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of @edition use project.edition

And more importantly I'd rather use query for that. You can add migration to link Week with Task model and then do in project loop:

results = project.tasks.joins(:week).group("weeks.id").count -> will return hash with week_id and number of tasks  
results.length == 12 -> award badge

@tasks = project.tasks.where(week: week.number)
if (@tasks.count < 1)
is_organised_flag = false
break
end
end
if (is_organised_flag)
print project.title
assign_organised_badge(project)
end
end
end

private
def assign_organised_badge(project)
unless project.mentee.badges.timekeeper.any?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

project.mentee.badges << Badge.organized
end
end

end