feeds 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ #source 'http://rubygems.org'
2
+ source :gemcutter
3
+
4
+ gem 'rails', '3.0.0.rc2'
5
+
6
+ gem 'activities'
7
+
8
+ #group :development do
9
+ # gem 'jeweler', :git => 'git://github.com/technicalpickles/jeweler.git'
10
+ #end
11
+
12
+ # Bundle gems for the local environment. Make sure to
13
+ # put test-only gems in this group so their generators
14
+ # and rake tasks are available in development mode:
15
+ group :test, :development do
16
+ gem "rspec-rails", ">= 2.0.0.beta.19"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ GIT
2
+ remote: git://github.com/technicalpickles/jeweler.git
3
+ revision: 62f2651
4
+ specs:
5
+ jeweler (1.5.0.pre)
6
+ bundler (>= 1.0.0.rc.5)
7
+ git (>= 1.2.5)
8
+ rake
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ abstract (1.0.0)
14
+ actionmailer (3.0.0.rc2)
15
+ actionpack (= 3.0.0.rc2)
16
+ mail (~> 2.2.5)
17
+ actionpack (3.0.0.rc2)
18
+ activemodel (= 3.0.0.rc2)
19
+ activesupport (= 3.0.0.rc2)
20
+ builder (~> 2.1.2)
21
+ erubis (~> 2.6.6)
22
+ i18n (~> 0.4.1)
23
+ rack (~> 1.2.1)
24
+ rack-mount (~> 0.6.12)
25
+ rack-test (~> 0.5.4)
26
+ tzinfo (~> 0.3.23)
27
+ activemodel (3.0.0.rc2)
28
+ activesupport (= 3.0.0.rc2)
29
+ builder (~> 2.1.2)
30
+ i18n (~> 0.4.1)
31
+ activerecord (3.0.0.rc2)
32
+ activemodel (= 3.0.0.rc2)
33
+ activesupport (= 3.0.0.rc2)
34
+ arel (~> 1.0.0.rc1)
35
+ tzinfo (~> 0.3.23)
36
+ activeresource (3.0.0.rc2)
37
+ activemodel (= 3.0.0.rc2)
38
+ activesupport (= 3.0.0.rc2)
39
+ activesupport (3.0.0.rc2)
40
+ activities (0.1.1)
41
+ arel (1.0.0.rc1)
42
+ activesupport (>= 3.0.0.beta)
43
+ builder (2.1.2)
44
+ diff-lcs (1.1.2)
45
+ erubis (2.6.6)
46
+ abstract (>= 1.0.0)
47
+ git (1.2.5)
48
+ i18n (0.4.1)
49
+ mail (2.2.5)
50
+ activesupport (>= 2.3.6)
51
+ mime-types
52
+ treetop (>= 1.4.5)
53
+ mime-types (1.16)
54
+ polyglot (0.3.1)
55
+ rack (1.2.1)
56
+ rack-mount (0.6.12)
57
+ rack (>= 1.0.0)
58
+ rack-test (0.5.4)
59
+ rack (>= 1.0)
60
+ rails (3.0.0.rc2)
61
+ actionmailer (= 3.0.0.rc2)
62
+ actionpack (= 3.0.0.rc2)
63
+ activerecord (= 3.0.0.rc2)
64
+ activeresource (= 3.0.0.rc2)
65
+ activesupport (= 3.0.0.rc2)
66
+ bundler (>= 1.0.0.rc.6)
67
+ railties (= 3.0.0.rc2)
68
+ railties (3.0.0.rc2)
69
+ actionpack (= 3.0.0.rc2)
70
+ activesupport (= 3.0.0.rc2)
71
+ rake (>= 0.8.3)
72
+ thor (~> 0.14.0)
73
+ rake (0.8.7)
74
+ rspec (2.0.0.beta.20)
75
+ rspec-core (= 2.0.0.beta.20)
76
+ rspec-expectations (= 2.0.0.beta.20)
77
+ rspec-mocks (= 2.0.0.beta.20)
78
+ rspec-core (2.0.0.beta.20)
79
+ rspec-expectations (2.0.0.beta.20)
80
+ diff-lcs (>= 1.1.2)
81
+ rspec-mocks (2.0.0.beta.20)
82
+ rspec-rails (2.0.0.beta.20)
83
+ rspec (= 2.0.0.beta.20)
84
+ thor (0.14.0)
85
+ treetop (1.4.8)
86
+ polyglot (>= 0.3.1)
87
+ tzinfo (0.3.23)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ activities
94
+ jeweler!
95
+ rails (= 3.0.0.rc2)
96
+ rspec-rails (>= 2.0.0.beta.19)
data/README ADDED
@@ -0,0 +1,2 @@
1
+ Feeds!
2
+
data/VERSION ADDED
@@ -0,0 +1,2 @@
1
+ 0.0.1
2
+
@@ -0,0 +1,5 @@
1
+ class Activity < ::ActiveRecord::Base
2
+ belongs_to :tracker, :polymorphic => true
3
+ belongs_to :trackable, :polymorphic => true
4
+ serialize :data, Hash
5
+ end
data/lib/feeds.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Feeds
2
+ require 'feeds/init' if defined?(Rails)
3
+ require 'feeds/active_record'
4
+ end
@@ -0,0 +1 @@
1
+ require "feeds/active_record/activities"
@@ -0,0 +1,20 @@
1
+ module Feeds
2
+ def self.included(base)
3
+ base.send :extend, ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ # any method placed here will apply to classes, like Hickwall
8
+ def feeds_for(*activities_options, &block)
9
+ self.class_eval do
10
+ activities_for(*activities_options, &block)
11
+ end
12
+ send :include, InstanceMethods
13
+ end
14
+ end
15
+
16
+ module InstanceMethods
17
+ end
18
+ end
19
+
20
+ ActiveRecord::Base.send :include, Feeds
data/lib/feeds/init.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rails"
2
+
3
+ module Feeds
4
+ class Engine < Rails::Engine
5
+
6
+ rake_tasks do
7
+ load "tasks/feeds.rake"
8
+ end
9
+
10
+ end
11
+ end
File without changes
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Feeds
5
+ module Generators
6
+ class MigrationGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ desc "Run this generator to create setup migrations"
10
+
11
+ # Implement the required interface for Rails::Generators::Migration.
12
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
13
+ def self.next_migration_number(dirname)
14
+ @n ||= 0
15
+ if ActiveRecord::Base.timestamped_migrations
16
+ @n += 1
17
+ (Time.now + @n.seconds).utc.strftime("%Y%m%d%H%M%S")
18
+ else
19
+ "%.3d" % (current_migration_number(dirname) + 1)
20
+ end
21
+ end
22
+
23
+ def self.source_root
24
+ @source_root = File.join(File.dirname(__FILE__), '../templates')
25
+ end
26
+
27
+ def create_migrations_file
28
+ migration_template "create_activities.rb", "db/migrate/sp_create_activities_table.rb"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ class SpCreateActivitiesTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :activities do |t|
4
+ t.references :tracker, :polymorphic => true, :null => false
5
+ t.references :trackable, :polymorphic => true, :null => false
6
+ t.string :action, :null => false
7
+ t.text :data, :null => true
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :activities, [:tracker_id, :trackable_id]
12
+ add_index :activities, [:tracker_id, :trackable_id, :action]
13
+ end
14
+
15
+ def self.down
16
+ drop_table :activities
17
+ end
18
+ end
File without changes
@@ -0,0 +1,165 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
+
3
+ class User < ActiveRecord::Base
4
+ include SpRanking
5
+
6
+ acts_as_rankable
7
+ end
8
+
9
+ describe SpRanking do
10
+ load_schema
11
+
12
+ describe 'acts_as_rankable relationships' do
13
+ it 'should have many points_histories' do
14
+ u = create_user
15
+ lambda do
16
+ u.points_histories
17
+ end.should_not raise_error
18
+ end
19
+ end
20
+
21
+ describe 'callbacks -> ' do
22
+ describe 'after_create' do
23
+ it 'should set end date.' do
24
+ ranking = Ranking.create(:start_date => Date.today, :interval => 1, :interval_type => 'weekly')
25
+ ranking.end_date.should == Date.today + 7.days
26
+ ranking.destroy
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'model Ranking scopes' do
32
+ describe ':actives' do
33
+ it 'should return all active rankings and the general if rankrank' do
34
+ rankings = Ranking.actives
35
+ rankings.collect(&:name).should include(RANKING_CONFIG.keys.first.to_s)
36
+ rankings.each do |rank|
37
+ unless rank.name == RANKING_CONFIG.keys.first.to_s
38
+ rank.start_date.should <= Date.today
39
+ rank.end_date.should > Date.today
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ describe ':expired' do
46
+ before :all do
47
+ @ranking = Ranking.create(:name => 'asdf', :start_date => Date.yesterday, :end_date => Date.today)
48
+ end
49
+ after :all do
50
+ @ranking.destroy
51
+ end
52
+
53
+ it 'should return all ranking where end_date = Date.today' do
54
+ rankings = Ranking.expired
55
+ rankings.each do |rank|
56
+ rank.end_date.should == Date.today
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ describe 'creating user' do
63
+ it 'points should be 0 in a new user by default' do
64
+ u = create_user
65
+ RANKING_CONFIG.keys.each do |ranking|
66
+ u["points_#{ranking}".to_sym].should == 0
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'score method' do
72
+ it 'should increment user points by value passed as param' do
73
+ u = create_user
74
+ u.score(10)
75
+ u.reload
76
+ RANKING_CONFIG.keys.each do |ranking|
77
+ u["points_#{ranking}".to_sym].should == 10
78
+ end
79
+ end
80
+
81
+ it 'should increment points on active rankings only' do
82
+ RANKING_CONFIG.each_pair do |ranking, options|
83
+ Ranking.create!(:name => ranking, :start_date => Date.today - 2.days, :end_date => Date.today - 1.day)
84
+ end
85
+ u = create_user
86
+ u.score(5)
87
+ u.reload
88
+ RANKING_CONFIG.keys.each do |ranking|
89
+ u["points_#{ranking}".to_sym].should == 5
90
+ end
91
+ end
92
+ end
93
+ #=begin
94
+ describe 'updating rankings' do
95
+ before :each do
96
+ ###
97
+ end
98
+ before :all do
99
+ @user = create_user(:points => true)
100
+ @points_history_count = PointsHistory.count
101
+ @today = Date.today
102
+ Date.stub!(:today).and_return(@today + 7.days)
103
+ @month_points = @user.points_month_rank
104
+ @week_points = @user.points_week_rank
105
+ @ranking_count = Ranking.count
106
+ Ranking.save_history
107
+ end
108
+
109
+
110
+ describe 'saving points histories' do
111
+ it 'should create a new entry in the points_histories table' do
112
+ PointsHistory.count.should == @points_history_count + User.count
113
+ end
114
+
115
+ it 'should reset user week points' do
116
+ @user.reload
117
+ @user.points_week_rank.should == 0
118
+ end
119
+
120
+ it 'should left month points unchanged' do
121
+ @user.points_month_rank.should == @month_points
122
+ end
123
+ end
124
+
125
+
126
+ describe 'creating a new ranking with a new end_date' do
127
+ it 'should create a new ranking' do
128
+ Ranking.count.should == @ranking_count + 1
129
+ end
130
+
131
+ it 'should set the new ranking start_date as today' do
132
+ new_ranking = Ranking.find_all_by_start_date_and_name(Date.today, "week_rank")
133
+ new_ranking.size.should == 1
134
+ end
135
+
136
+ it 'should set the new ranking end_date as date.today + 7.days' do
137
+ new_ranking = Ranking.find_all_by_end_date_and_name(Date.today + 7.days, "week_rank")
138
+ new_ranking.size.should == 1
139
+ end
140
+ end
141
+ end
142
+ #=end
143
+ private
144
+
145
+ def create_user(options={:points => false})
146
+ full_options = user_valid_attributes.merge(options)
147
+ full_options.merge!(user_points) if options[:points]
148
+ full_options.delete(:points)
149
+ #p full_options
150
+ User.create(full_options)
151
+ end
152
+
153
+ def user_valid_attributes
154
+ {:name => "DinoSauro"}
155
+ end
156
+
157
+ def user_points(options = {})
158
+ points = {}
159
+ RANKING_CONFIG.each_key do |name|
160
+ points.merge!("points_#{name}".to_sym => 666)
161
+ end
162
+ points.merge(options)
163
+ end
164
+
165
+ end
@@ -0,0 +1,7 @@
1
+ mysql:
2
+ :adapter: mysql
3
+ :host: localhost
4
+ :username: root
5
+ :password:
6
+ :database: ps_ranking_test
7
+
data/spec/db/schema.rb ADDED
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'generators', 'helpers', 'ranking_helper.rb')
2
+ include SpRanking::Generators::Helpers
3
+
4
+ ActiveRecord::Schema.define(:version => 0) do
5
+ create_table :users, :force => true do |t|
6
+ RANKING_CONFIG.keys.each do |ranking|
7
+ t.integer "points_#{ranking}".to_sym, :default => 0
8
+ end
9
+ t.string :name
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :points_histories, :force => true do |t|
14
+ t.integer :ranking_id
15
+ t.integer :points
16
+ t.integer :user_id
17
+ t.timestamps
18
+ end
19
+ add_index :points_histories, :ranking_id
20
+ add_index :points_histories, :user_id
21
+
22
+ create_table :rankings, :force => true do |t|
23
+ t.string :name
24
+ t.date :start_date
25
+ t.date :end_date
26
+ t.string :interval_type
27
+ t.integer :interval
28
+ t.timestamps
29
+ end
30
+ RANKING_CONFIG.each_pair do |ranking_name, options|
31
+ Ranking.create(:name => ranking_name, :start_date => options['start_date'], :end_date => calculate_end_date(options['start_date'], options['interval'], options['type']), :interval_type => options['type'], :interval => options['interval'] || nil)
32
+ end
33
+
34
+ end
@@ -0,0 +1,30 @@
1
+ # this is a config file for the rankings you want to create in your app.
2
+ # You can create as many types of ranking as you want.
3
+ # Set the type and interval to change behaviour, like:
4
+ # ...
5
+ # Example:
6
+ #general_rank:
7
+ # type: general
8
+ # interval:
9
+ # start_date:
10
+ #
11
+ #month_rank:
12
+ # type: monthly
13
+ # interval: 1
14
+ # start_date: 2010-08-20
15
+
16
+ general_rank:
17
+ type: general
18
+ interval:
19
+ start_date:
20
+
21
+ month_rank:
22
+ type: monthly
23
+ interval: 1
24
+ start_date: <%= Date.today.strftime("%Y-%m-%d") %>
25
+
26
+ week_rank:
27
+ type: weekly
28
+ interval: 1
29
+ start_date: <%= Date.today.strftime("%Y-%m-%d") %>
30
+
@@ -0,0 +1,41 @@
1
+ require 'rails/all'
2
+ require 'rspec'
3
+ require 'date'
4
+ require File.join(File.dirname(__FILE__), '../lib/generators/helpers/ranking_helper.rb')
5
+ require File.join(File.dirname(__FILE__), '../lib/ranking.rb')
6
+ require File.join(File.dirname(__FILE__), '../app/models/points_history.rb')
7
+ require File.join(File.dirname(__FILE__), '../app/models/ranking.rb')
8
+
9
+ RANKING_CONFIG = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'rankings.yml'))).result).symbolize_keys
10
+
11
+ #Rails.env = 'test'
12
+ #ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
13
+
14
+ def load_schema
15
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/db/database.yml'))
16
+ #ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
17
+
18
+ db_adapter = ENV['DB']
19
+
20
+ # no db passed, try one of these fine config-free DBs before bombing.
21
+ db_adapter ||=
22
+ begin
23
+ require 'rubygems'
24
+ require 'mysql'
25
+ 'mysql'
26
+ rescue MissingSourceFile
27
+ begin
28
+ require 'sqlite3'
29
+ 'sqlite3'
30
+ rescue MissingSourceFile
31
+ end
32
+ end
33
+
34
+ if db_adapter.nil?
35
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
36
+ end
37
+
38
+ ActiveRecord::Base.establish_connection(config[db_adapter])
39
+ load(File.dirname(__FILE__) + "/db/schema.rb")
40
+ #require File.dirname(__FILE__) + '/../rails/init'
41
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feeds
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Pedro Pires
13
+ - Sergio Henrique TP
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-27 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Activities feeds using the gem 'activities' by Nando Vieira
23
+ email: suporte@dito.com.br
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - .bundle/config
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - README
35
+ - VERSION
36
+ - app/models/activity.rb
37
+ - lib/feeds.rb
38
+ - lib/feeds/active_record.rb
39
+ - lib/feeds/active_record/activities.rb
40
+ - lib/feeds/init.rb
41
+ - lib/generators/feeds/feeds_for_generator.rb
42
+ - lib/generators/feeds/migration_generator.rb
43
+ - lib/generators/templates/create_activities.rb
44
+ - lib/tasks/feeds.rake
45
+ - spec/acts_as_rankable_spec.rb
46
+ - spec/db/database.yml
47
+ - spec/db/schema.rb
48
+ - spec/fixtures/rankings.yml
49
+ - spec/spec_helper.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/dito/feeds
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Activities feeds.
82
+ test_files: []
83
+