From c6313619ddab800cf898d2f4e9fa677b7e4dcb31 Mon Sep 17 00:00:00 2001 From: MDaubs Date: Tue, 3 May 2011 18:44:33 -0400 Subject: [PATCH] Initial commit. --- Gemfile | 3 +++ README.rdoc | 23 ++++++++++++++++++++--- Rakefile | 4 ++-- lib/recurring_helpers.rb | 14 ++++++++++++++ test/helper.rb | 29 ++++++++++++++++++++++++++++- test/test_recurring_helpers.rb | 5 +---- 6 files changed, 68 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index cc25d95..997b54f 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,12 @@ source "http://rubygems.org" # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. +gem "rails" +gem "ri_cal" group :development do gem "shoulda", ">= 0" gem "bundler", "~> 1.0.0" gem "jeweler", "~> 1.6.0" gem "rcov", ">= 0" + gem "sqlite3" end diff --git a/README.rdoc b/README.rdoc index 7073a5e..0803d28 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,6 +1,24 @@ = recurring_helpers -Description goes here. +This is a gem intended for private consumption! You are welcome to use it but I suggest you fork it first. Things may suddenly and drastically change on a whime! + +== What's this for? + +Recurring_helpers is a library of various tools for dealing with recurring events. It is essentially glue between an application's event-like model, the event-calendar gem, and the ri_cal gem. Some of the superpowers it gives event-like models are iCal export, recurring occurrence caching, and conflict detection. As a bonus you also get some view helpers for making it easier to deal with recurring event rules. + +== Setup your event-like model + + class Event < ActiveModel::Base + # The EventOccurrence model is updated automatically when Event is saved + has_many :event_occurrences + # The EventRule model should be user-updatable, it's attributes being directly set by a user interface + has_many :event_rules + # The is_recurring macro extends Event so that when it is saved an iCal file is generated, cached into the attribute cached_ical, and the event_occurrences collection is generated based on the rules, start, and end times. The event_occurrences collection should not be modified by the end user and treated as a read-only cache. The purpose of this is to simplify the logic needed by event-calendar to draw a pretty calendar. It allows event occurrences to be queried with little effort at the expense of a slightly more expensive save action. + is_recurring + end + +== Setup your user interface + == Contributing to recurring_helpers @@ -14,6 +32,5 @@ Description goes here. == Copyright -Copyright (c) 2011 MDaubs. See LICENSE.txt for -further details. +Copyright (c) 2011 Matthew Daubert. See LICENSE.txt for further details. diff --git a/Rakefile b/Rakefile index bc43550..a7364b3 100644 --- a/Rakefile +++ b/Rakefile @@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem| gem.name = "recurring_helpers" gem.homepage = "http://github.com/mdaubs/recurring_helpers" gem.license = "MIT" - gem.summary = %Q{TODO: one-line summary of your gem} - gem.description = %Q{TODO: longer description of your gem} + gem.summary = %Q{Give event-like models super-human recurring powers. Includes iCal export, interface helpers for recurrence rules, and view helpers for event-calendar.} + gem.description = %Q{Give event-like models super-human recurring powers. Includes iCal export, interface helpers for recurrence rules, and view helpers for event-calendar.} gem.email = "mdaubert@gmail.com" gem.authors = ["MDaubs"] # dependencies defined in Gemfile diff --git a/lib/recurring_helpers.rb b/lib/recurring_helpers.rb index e69de29..0bb09ca 100644 --- a/lib/recurring_helpers.rb +++ b/lib/recurring_helpers.rb @@ -0,0 +1,14 @@ +require 'rails' +require 'tzinfo' +require 'active_support/all' +require 'ri_cal' +require 'active_record' +require 'recurring_helpers/rails' + +module RecurringHelpers + autoload :RecurringModel, 'recurring_helpers/recurring_model' + autoload :ActiveRecord, 'recurring_helpers/active_record' + +end + +ActiveRecord::Base.extend RecurringHelpers::ActiveRecord diff --git a/test/helper.rb b/test/helper.rb index e4407ac..a038f30 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -14,5 +14,32 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'recurring_helpers' -class Test::Unit::TestCase +#Setup defaults otherwise set by Rails +Time.zone = "America/New_York" + +#Setup test database +ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") +ActiveRecord::Schema.define(:version => 1) do + create_table :events do |t| + t.string :description + t.string :summary + t.datetime :start_at + t.datetime :end_at + t.boolean :all_day, :default => false + t.text :cached_ical + end + create_table :event_occurrences do |t| + t.datetime :start_at + t.datetime :end_at + t.integer :event_id + end + create_table :event_rules do |t| + t.integer :count + t.datetime :until + t.string :freq + t.integer :interval + t.string :wkst + t.boolean :exclusion + t.integer :event_id + end end diff --git a/test/test_recurring_helpers.rb b/test/test_recurring_helpers.rb index 90d31a2..3195814 100644 --- a/test/test_recurring_helpers.rb +++ b/test/test_recurring_helpers.rb @@ -1,7 +1,4 @@ require 'helper' -class TestRecurringHelpers < Test::Unit::TestCase - should "probably rename this file and start testing for real" do - flunk "hey buddy, you should probably rename this file and start testing for real" - end +class TestRecurringHelpers < ActiveSupport::TestCase end