Permalink
Browse files

Remove Garb, added page_views increment

  • Loading branch information...
1 parent 43c72be commit 26dc226a88a8182bc5ac519c793f779442f1c42d @makaroni4 makaroni4 committed Feb 12, 2013
Showing with 17 additions and 72 deletions.
  1. +0 −1 Gemfile
  2. +0 −12 Gemfile.lock
  3. +2 −1 app/controllers/posts_controller.rb
  4. +0 −28 app/models/ga.rb
  5. +1 −14 config/deploy.rb
  6. +0 −4 config/schedule.rb
  7. +0 −12 lib/tasks/posts.rake
  8. +14 −0 spec/controllers/posts_controller_spec.rb
View
@@ -24,7 +24,6 @@ gem 'diffy'
gem 'rails_emoji'
gem 'sanitize'
gem 'whenever'
-gem 'garb'
gem 'geocoder'
gem 'relish'
gem 'tire'
View
@@ -92,7 +92,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.4.0)
- crack (0.3.2)
daemons (1.1.9)
database_cleaner (0.9.1)
diff-lcs (1.1.3)
@@ -113,9 +112,6 @@ GEM
faye-websocket (0.4.6)
eventmachine (>= 0.12.0)
ffi (1.3.1)
- garb (0.9.1)
- activesupport (>= 2.2.0)
- crack (>= 0.1.6)
geocoder (1.1.6)
github-markdown (0.5.3)
guard (1.6.2)
@@ -226,13 +222,6 @@ GEM
activerecord (~> 3.0)
polyamorous (~> 0.5.0)
rdoc (3.12.1)
- ransack (0.7.3)
- actionpack (~> 3.0)
- activerecord (~> 3.0)
- polyamorous (~> 0.5.0)
- rdoc (3.12)
- json (~> 1.4)
- rdoc (3.12.1)
redis (3.0.2)
redis-actionpack (3.2.3)
actionpack (~> 3.2.3)
@@ -373,7 +362,6 @@ DEPENDENCIES
diffy
factory_girl_rails
faker
- garb
geocoder
github-markdown
guard-rspec
@@ -26,8 +26,9 @@ def bookmarks
def show
@post = Post.find_by_param params[:id]
- redirect_to(@post, status: 301) if params[:id] != @post.to_param
+ redirect_to(@post, status: 301) if params[:id] != @post.to_param
@comment = @post.comments.build if can? :create, :comments
+ @post.increment!(:page_views)
end
def new
View
@@ -1,28 +0,0 @@
-class GA
- extend Garb::Model
-
- metrics :pageviews
- dimensions :page_path
-
- attr_reader :profile
-
- def initialize
- Garb::Session.login(
- Configuration.google_analytics.login,
- Configuration.google_analytics.password
- )
-
- @profile = Garb::Management::Profile.all.detect do |profile|
- profile.web_property_id == Configuration.google_analytics.web_property_id
- end
- end
-
- def page_views post
- GA.results(
- profile,
- :filters => { :page_path.eql => post.path },
- :start_date => 5.years.ago.to_date,
- :end_date => Date.today
- ).to_a.first.try(:pageviews)
- end
-end
View
@@ -40,18 +40,6 @@
end
end
-# namespace :db_migrations do
-# task :run do
-# from = source.next_revision(current_revision)
-# if capture("cd #{latest_release} && #{source.local.log(from)} db/migrate | wc -l").to_i > 0
-# run "cd #{current_release} && RAILS_ENV=#{rails_env} bin/rake db:migrate"
-# logger.info "New migrations added - running migrations."
-# else
-# logger.info "Skipping migrations - there are not any new."
-# end
-# end
-# end
-
namespace :deploy do
task :restart do
end
@@ -68,5 +56,4 @@
end
end
-after 'deploy:finalize_update', 'deploy:make_symlinks'
-# after 'deploy:make_symlinks', 'db_migrations:run'
+after 'deploy:finalize_update', 'deploy:make_symlinks'
View
@@ -8,10 +8,6 @@
rake 'time_counters:generate_todays'
end
-every 1.hour do
- rake 'posts:update_page_views'
-end
-
every 1.day do
rake 'users:fetch_locations'
end
View
@@ -1,12 +0,0 @@
-namespace :posts do
- task update_page_views: :environment do
- google_analytics = GA.new
-
- Post.find_each do |post|
- page_views = google_analytics.page_views post
- post.update_attribute(:page_views, page_views) if page_views
- end
-
- Rails.cache.clear
- end
-end
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe PostsController do
+ render_views
+ let!(:post) { create :post }
+
+ describe 'GET show' do
+ it 'increments page_views' do
+ expect {
+ get :show, :id => post.to_param
+ }.to change { post.reload.page_views }.by(1)
+ end
+ end
+end

0 comments on commit 26dc226

Please sign in to comment.