Skip to content

Commit

Permalink
merge changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Nov 4, 2008
2 parents 881c38e + fca579a commit 6260b29
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 22 deletions.
8 changes: 3 additions & 5 deletions .gitignore
@@ -1,5 +1,3 @@
config/environment.rb
app/config.ru
app/config.rb
app/tmp
app/*.log
config.ru
config.rb
tmp
8 changes: 3 additions & 5 deletions README
Expand Up @@ -19,22 +19,21 @@ rake seinfeld:add_user USER=technoweenie
rake seinfeld:update

# let's start the show
cd app
ruby seinfeld_calendar.rb
open http://localhost:4567/~technoweenie

DEPLOYMENT
==========

My app/config.rb looks like this:
My config.rb looks like this:

$: << File.join(File.dirname(__FILE__), '..', 'lib')
$: << File.join(File.dirname(__FILE__), 'lib')
require 'seinfeld/models'
DataMapper.setup :default, 'mysql://rickybobby:shakeandbake@localhost/seinfeld'
Seinfeld::User.github_login = 'rickybobby'
Seinfeld::User.github_password = 'shakeandbake'

My app/config.ru (for Passenger) looks like:
My config.ru (for Passenger) looks like:

require 'rubygems'
require 'rack'
Expand All @@ -43,7 +42,6 @@ My app/config.ru (for Passenger) looks like:
Sinatra::Application.default_options.update(
:run => false,
:env => :production,
:views => '/path/to/seinfeld/app/views', # sinatra looks in the wrong place
:raise_errors => true
)

Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Expand Up @@ -14,7 +14,7 @@ task :default => 'spec'

namespace :seinfeld do
task :init do
require 'app/config'
require 'config'
end

task :setup => :init do
Expand All @@ -41,4 +41,9 @@ namespace :seinfeld do
end
end
end

task :reset => :init do
raise "Need USER=" if ENV['USER'].to_s.size.zero?
Seinfeld::User.first(:login => ENV['USER']).reset_progress
end
end
2 changes: 1 addition & 1 deletion config/rackup.ru
Expand Up @@ -5,7 +5,7 @@ Seinfeld::User.github_login = 'calendaraboutnothing'
Seinfeld::User.github_password = 'zwol8wak3r'
Seinfeld::User.creation_token = 'ba2da61bf433cc0d5b036d7739dd35f8acca6e34'

require File.dirname(__FILE__) + "/../app/seinfeld_calendar.rb"
require File.dirname(__FILE__) + "/../seinfeld_calendar.rb"

disable :run, :reload
set :env, :production
Expand Down
25 changes: 17 additions & 8 deletions lib/seinfeld/models.rb
@@ -1,11 +1,5 @@
$: << File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'activesupport-2.1.1', 'lib')
$: << File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'mechanize-0.8.4', 'lib')
$: << File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'tzinfo-0.3.11', 'lib')

$: << File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'feed_me', 'lib')
$: << File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'mechanical_github', 'lib')
$LOAD_PATH.push *Dir[File.join(File.dirname(__FILE__), '..', '..', 'vendor', '*', 'lib')]
require 'rubygems'
#gem 'activesupport', '~> 2.1'
require 'active_support/time_with_zone'
require 'active_support/values/time_zone'
require 'active_support/core_ext/object'
Expand Down Expand Up @@ -66,6 +60,21 @@ def self.best_alltime_streak
all :longest_streak.gt => 0, :order => [:longest_streak.desc, :login], :limit => 15
end

def reset_progress
clear_progress
update_progress
end

def clear_progress
transaction do
progressions.destroy!
update_attributes \
:streak_start => nil, :streak_end => nil, :current_streak => nil,
:longest_streak => nil, :longest_streak_start => nil, :longest_streak_end => nil,
:last_entry_id => nil
end
end

def update_progress
transaction do
days = committed_days_in_feed || []
Expand Down Expand Up @@ -141,7 +150,7 @@ def progress_for(year, month)
end

def longest_streak_url
if longest_streak_start.nil? || longest_streak_start.nil?
if longest_streak_start.nil? || longest_streak_end.nil?
"/~#{login}"
else
"/~#{login}/#{longest_streak_start.year}/#{longest_streak_start.month}"
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions app/seinfeld_calendar.rb → seinfeld_calendar.rb
@@ -1,6 +1,6 @@
unless Object.const_defined?(:Seinfeld)
# setup a config.ru for rack, or some other ruby config file
$: << File.join(File.dirname(__FILE__), '..', 'lib')
$: << File.join(File.dirname(__FILE__), 'lib')
require 'seinfeld/models'
DataMapper.setup :default, 'mysql://localhost/seinfeld'
end
Expand Down Expand Up @@ -56,7 +56,7 @@ def page_title

def get_user_and_progressions
[:year, :month].each do |key|
value = params[key].to_i
value = params[key].to_i
params[key] = value.zero? ? Date.today.send(key) : value
end
if @user = Seinfeld::User.first(:login => params[:name])
Expand Down
92 changes: 92 additions & 0 deletions spec/user_spec.rb
Expand Up @@ -91,6 +91,98 @@ module Seinfeld
end
end

describe "#clear_progress" do
before :all do
Seinfeld::User.transaction do
@existing = Seinfeld::User.create :login => 'bob',
:streak_start => Date.civil(2007, 12, 30), :streak_end => Date.civil(2007, 12, 31), :current_streak => 2,
:longest_streak_start => Date.civil(2007, 12, 30), :longest_streak_end => Date.civil(2007, 12, 31), :longest_streak => 2,
:last_entry_id => 'abc'
@existing.progressions.create(:created_at => Date.civil(2007, 12, 30))
@existing.progressions.create(:created_at => Date.civil(2007, 12, 31))
end
@existing.clear_progress
@existing.reload
end

it "clears progression records" do
@existing.should have(0).progressions
end

it "clears #streak_start" do
@existing.streak_start.should == nil
end

it "clears #streak_end" do
@existing.streak_end.should == nil
end

it "clears #current_streak" do
@existing.current_streak.should == nil
end

it "clears #longest_streak_start" do
@existing.longest_streak_start.should == nil
end

it "clears #longest_streak_end" do
@existing.longest_streak_end.should == nil
end

it "clears #longest_streak" do
@existing.longest_streak.should == nil
end

it "clears #last_entry_id" do
@existing.last_entry_id.should == nil
end
end

describe "#reset_progress" do
before :all do
Seinfeld::User.transaction do
@existing = Seinfeld::User.create :login => 'bob',
:streak_start => Date.civil(2007, 12, 15), :streak_end => Date.civil(2007, 12, 16), :current_streak => 1,
:longest_streak_start => Date.civil(2007, 12, 15), :longest_streak_end => Date.civil(2007, 12, 16), :longest_streak => 1,
:last_entry_id => 'abc'
@existing.progressions.create(:created_at => Date.civil(2007, 12, 15))
@existing.progressions.create(:created_at => Date.civil(2007, 12, 16))
end
@existing.stub!(:committed_days_in_feed).and_return [Date.civil(2007, 12, 30), Date.civil(2007, 12, 31), Date.civil(2008, 1, 1), Date.civil(2008, 1, 2)]
Date.stub!(:today).and_return(Date.civil(2008, 1, 3))
@existing.reset_progress
@existing.reload
end

it "resets progression records" do
@existing.progressions.map { |p| p.created_at }.should == [Date.civil(2008, 1, 2), Date.civil(2008, 1, 1), Date.civil(2007, 12, 31), Date.civil(2007, 12, 30)]
end

it "resets #streak_start" do
@existing.streak_start.should == Date.civil(2007, 12, 30)
end

it "resets #streak_end" do
@existing.streak_end.should == Date.civil(2008, 1, 2)
end

it "resets #current_streak" do
@existing.current_streak.should == 4
end

it "resets #longest_streak_start" do
@existing.longest_streak_start.should == Date.civil(2007, 12, 30)
end

it "resets #longest_streak_end" do
@existing.longest_streak_end.should == Date.civil(2008, 1, 2)
end

it "resets #longest_streak" do
@existing.longest_streak.should == 4
end
end

describe "#update_progress" do
before do
@user.stub!(:committed_days_in_feed).and_return [Date.civil(2008, 1, 1), Date.civil(2008, 1, 2)]
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 6260b29

Please sign in to comment.