by_star 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ class Post < ActiveRecord::Base
2
+ default_scope :order => "#{quoted_table_name}.created_at ASC"
3
+ has_and_belongs_to_many :tags
4
+
5
+ def self.factory(text, created_at = nil)
6
+ create!(:text => text, :created_at => created_at)
7
+ end
8
+ end
9
+
10
+ class Tag < ActiveRecord::Base
11
+ has_and_belongs_to_many :posts
12
+ end
13
+
14
+ class Event < ActiveRecord::Base
15
+ named_scope :private, :conditions => { :public => false }
16
+ end
17
+
18
+ ## seed data:
19
+
20
+ year = Time.zone.now.year
21
+
22
+ 1.upto(12) do |month|
23
+ month.times do |n|
24
+ Post.factory "post #{n}", Time.local(year, month, 1)
25
+ end
26
+ end
27
+
28
+ Post.factory "Today's post", Time.zone.now
29
+ Post.factory "Yesterday's post", Time.zone.now - 1.day
30
+ Post.factory "Tomorrow's post", Time.zone.now + 1.day
31
+
32
+ Post.factory "That's it!", Time.zone.now.end_of_year
33
+
34
+ # For by_weekend scoped test
35
+ post = Post.factory "Weekend of May", "16-05-2009".to_time
36
+ post.tags.create(:name => "weekend")
37
+
38
+ # For by_day scoped test
39
+ post = Post.factory "Today", Time.zone.now
40
+ post.tags.create(:name => "today")
41
+
42
+ # For yesterday scoped test
43
+ post = Post.factory "Yesterday", Time.zone.now.yesterday
44
+ post.tags.create(:name => "yesterday")
45
+
46
+ # For tomorrow scoped test
47
+ post = Post.factory "Tomorrow's Another Day", Time.zone.now.tomorrow
48
+ post.tags.create(:name => "tomorrow")
49
+
50
+ post = Post.factory "Last year", Time.local(year - 1, 1, 1)
51
+ post.tags.create(:name => "ruby")
52
+
53
+ post = Post.factory "The 'Current' Fortnight", Time.local(year, 5, 15)
54
+ post.tags.create(:name => "may")
55
+
56
+ post = Post.factory "The 'Current' Week", Time.local(year, 5, 15)
57
+ post.tags.create(:name => "may2")
58
+
59
+
60
+ Event.create(:name => "Ryan's birthday!", :start_time => "04-12-#{Time.zone.now.year}".to_time)
61
+ Event.create(:name => "Dad's birthday!", :start_time => "05-07-#{Time.zone.now.year}".to_time)
62
+ Event.create(:name => "Mum's birthday!", :start_time => "17-11-#{Time.zone.now.year}".to_time)
63
+ Event.create(:name => "Today", :start_time => Time.zone.now)
64
+ Event.create(:name => "Yesterday", :start_time => Time.zone.now.yesterday)
65
+ Event.create(:name => "Tomorrow", :start_time => Time.zone.now.tomorrow)
66
+
67
+ # For by_weekend test
68
+ Event.create(:name => "1st of August", :start_time => "01-08-#{Time.zone.now.year}".to_time)
69
+
70
+ Event.create(:name => "FBI meeting", :start_time => "02-03-#{Time.zone.now.year}".to_time, :public => false)
@@ -0,0 +1,24 @@
1
+ ActiveRecord::Schema.define do
2
+ self.verbose = false
3
+
4
+ create_table :posts, :force => true do |t|
5
+ t.string :text
6
+ t.timestamps
7
+ end
8
+
9
+ create_table :posts_tags, :force => true, :id => false do |t|
10
+ t.integer :post_id, :tag_id
11
+ end
12
+
13
+ create_table :tags, :force => true do |t|
14
+ t.string :name
15
+ t.timestamps
16
+ end
17
+
18
+ create_table :events, :force => true do |t|
19
+ t.datetime :start_time, :end_time
20
+ t.string :name
21
+ t.boolean :public, :default => true
22
+ end
23
+
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'activerecord'
3
+ require 'fileutils'
4
+ FileUtils.mkdir_p("tmp")
5
+ ActiveRecord::Base.establish_connection(
6
+ :adapter => "sqlite3",
7
+ :database => ":memory:"
8
+ )
9
+
10
+ ActiveRecord::Base.logger = Logger.new("tmp/activerecord.log")
11
+ $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
12
+
13
+ require 'activesupport'
14
+ require 'by_star'
15
+ require 'spec'
16
+
17
+ # Define time zone before loading test_helper
18
+ zone = "UTC"
19
+ Time.zone = zone
20
+ ActiveRecord::Base.default_timezone = zone
21
+
22
+ load File.dirname(__FILE__) + "/fixtures/schema.rb"
23
+ load File.dirname(__FILE__) + "/fixtures/models.rb"
24
+
25
+ # bootstraping the plugin through init.rb
26
+ # tests how it would load in a real application
27
+ load File.dirname(__FILE__) + "/../rails/init.rb"
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: by_star
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Bigg
8
+ - "Mislav Marohni\xC4\x87"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-15 00:00:00 +10:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ description: ActiveRecord extension for easier date scopes and time ranges
27
+ email: radarlistener@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.markdown
34
+ files:
35
+ - .gitignore
36
+ - MIT-LICENSE
37
+ - README.markdown
38
+ - Rakefile
39
+ - VERSION
40
+ - by_star.gemspec
41
+ - lib/by_star.rb
42
+ - rails/init.rb
43
+ - spec/by_star_spec.rb
44
+ - spec/fixtures/models.rb
45
+ - spec/fixtures/schema.rb
46
+ - spec/spec_helper.rb
47
+ - tmp/.gitignore
48
+ has_rdoc: true
49
+ homepage: http://github.com/radar/by_star
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: ActiveRecord extension for easier date scopes and time ranges
76
+ test_files:
77
+ - spec/by_star_spec.rb
78
+ - spec/fixtures/models.rb
79
+ - spec/fixtures/schema.rb
80
+ - spec/spec_helper.rb