Permalink
Browse files

meh, as name is the only thing required change the rest of the args t…

…o a hash
  • Loading branch information...
1 parent 96208a1 commit 877f4cb49ab37cfbaa31e5bfe1a4acbb81bb8785 Eric Harrison committed Dec 2, 2011
Showing with 7 additions and 3 deletions.
  1. +5 −1 lib/subly.rb
  2. +2 −2 spec/subly_spec.rb
View
@@ -4,6 +4,7 @@
module Subly
def subly(args = {})
self.has_many :sublies, :as => :subscriber, :class_name => 'Subly::Model'
+ self.accepts_nested_attributes_for :sublies, :allow_destroy => true, :reject_if => :all_blank
#we don't want to use method missing for all "is" methods
if is_methods = args.delete(:is_methods)
@@ -36,7 +37,10 @@ def with_active_subscription(name)
end
module InstanceMethods
- def add_subscription(name, value = nil, start_date = Time.now, end_date = nil)
+ def add_subscription(name, args = {})
+ value = args[:value] || nil
+ start_date = args[:start_date] || Time.now
+ end_date = args[:end_date] || nil
self.sublies.create(:name => name, :value => value, :starts_at => start_date, :ends_at => end_date)
end
View
@@ -25,7 +25,7 @@ class Thing < ActiveRecord::Base
it "has_subscription should return true even for expired subscription" do
thing_one = Thing.create(:name => 'Thing One', :description => 'foo')
- thing_one.add_subscription('sub name',"value", Time.now - 1.day, Time.now - 2.hours).should be_true
+ thing_one.add_subscription('sub name', :start_date => Time.now - 1.day, :end_date => Time.now - 2.hours).should be_true
thing_one.reload
thing_one.has_subscription?('sub name').should be_true
end
@@ -41,7 +41,7 @@ class Thing < ActiveRecord::Base
it "should find models with even expired subscriptions" do
Thing.delete_all
thing_one = Thing.create(:name => 'Thing One', :description => 'foo')
- thing_one.add_subscription('sub name',"value",Time.now - 1.day, Time.now - 2.hours).should be_true
+ thing_one.add_subscription('sub name', :start_date => Time.now - 1.day, :end_date => Time.now - 2.hours).should be_true
Thing.with_subscription('sub name').should == [thing_one]
thing_one.destroy
end

0 comments on commit 877f4cb

Please sign in to comment.