Skip to content

Commit

Permalink
a new rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinicius Gomes committed Jan 2, 2012
1 parent 10a02d9 commit 5dbd209
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ task :cleandb do
Nightclubber.delete_all
Report.delete_all
puts 'done.'
end

task :news do
puts "Number of clubbers: #{Nightclubber.count}"
puts "Last added: #{Nightclubber.last.to_s}"
end
1 change: 0 additions & 1 deletion app/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def subscriber
post '/' do
@clubber = Nightclubber.parse(params)
if @clubber.save
subscriber.subscribe @clubber #bad
session[:subscribed] = true
redirect to '/done'
else
Expand Down
13 changes: 12 additions & 1 deletion app/models/nightclubber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class Nightclubber
field :name, :type => String
field :email, :type => String
field :friends, :type => Array, :default => []
field :time, :type => Time

validates_uniqueness_of :email

def initialize name, email, friends
super :name => name, :email => email, :friends => friends
super :name => name, :email => email, :friends => friends, :time => Time.now
end

def self.parse params
Expand All @@ -26,6 +27,16 @@ def self.sorted_names
def self.empty
Nightclubber.new('', '', ['', '', '', ''])
end

def to_s
"#{formated_time} - #{name} (#{email}) with #{friends.join(', ')}"
end

private

def formated_time
time.getlocal.strftime("%d/%m/%Y %I:%M%p")
end

end

6 changes: 6 additions & 0 deletions spec/models/nightclubber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
empty.email.should be_eql ''
empty.friends.each{|f| f.should be_eql ''}
end

it 'should be able to render itself as string' do
sabella = Nightclubber.new 'Filipe Sabella', '[email protected]', ['Marano', 'Pedro']
sabella.to_s.should match(
/\d\d\/\d\d\/\d\d\d\d \d\d:\d\d[AP]M - Filipe Sabella \([email protected]\) with Marano, Pedro/)
end

end

6 changes: 5 additions & 1 deletion todo.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
- the task subscribe doesn't make sense right now because I would like to trigger it from my localbox in eventual situations, like when there is a party for the current week which was added after monday. so that I could just point to the production database.
- consider: get to the party and subscribe everybody X take each one to all parties

- task to be run by heroku every monday
- task to be run by me

- acceptance specs

0 comments on commit 5dbd209

Please sign in to comment.