Permalink
Browse files

Merge branch 'master' of github.com:BlueHotDog/CodeNews

  • Loading branch information...
elentok committed Apr 21, 2012
2 parents 022c603 + cb28aa4 commit 61e8079a7ce9135f9b0332bd7c8cf386c1a8a65b
View
15 Gemfile
@@ -2,12 +2,6 @@ source 'https://rubygems.org'
gem 'rails', '3.2.1'
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
-
-gem 'sqlite3'
-
-
# Gems used only for assets and not required
# in production environments by default.
group :assets do
@@ -21,14 +15,19 @@ end
gem 'haml'
gem 'jquery-rails'
-gem 'debugger'
gem 'omniauth-github', :git => 'git://github.com/intridea/omniauth-github.git'
gem 'octokit'
gem 'omniauth-twitter', :git => 'https://github.com/arunagw/omniauth-twitter.git'
-
+gem 'heroku'
group :development do
gem 'rb-fsevent'
gem 'guard-livereload'
+ gem 'debugger'
+ gem 'sqlite3'
end
+group :production do
+ gem 'pg'
+ gem 'thin'
+end
View
@@ -58,6 +58,7 @@ GEM
execjs
coffee-script-source (1.3.1)
columnize (0.3.6)
+ daemons (1.1.8)
debugger (1.1.1)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1)
@@ -93,6 +94,11 @@ GEM
haml (~> 3.0)
railties (~> 3.0)
hashie (1.2.0)
+ heroku (2.19.2)
+ launchy (>= 0.3.2)
+ rest-client (~> 1.6.1)
+ rubyzip
+ term-ansicolor (~> 1.0.5)
hike (1.2.1)
httpauth (0.1)
i18n (0.6.0)
@@ -101,6 +107,8 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
+ launchy (2.0.5)
+ addressable (~> 2.2.6)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -128,6 +136,7 @@ GEM
omniauth-oauth2 (1.0.1)
oauth2 (~> 0.6.0)
omniauth (~> 1.0)
+ pg (0.13.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@@ -155,6 +164,9 @@ GEM
rb-fsevent (0.9.1)
rdoc (3.12)
json (~> 1.4)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rubyzip (0.9.6.1)
sass (3.1.16)
sass-rails (3.2.5)
railties (~> 3.2.0)
@@ -165,6 +177,11 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
+ term-ansicolor (1.0.7)
+ thin (1.3.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -186,12 +203,15 @@ DEPENDENCIES
guard-livereload
haml
haml-rails
+ heroku
jquery-rails
octokit
omniauth-github!
omniauth-twitter!
+ pg
rails (= 3.2.1)
rb-fsevent
sass-rails (~> 3.2.3)
sqlite3
+ thin
uglifier (>= 1.0.3)
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Vote controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,34 @@
+class VoteController < ApplicationController
+
+ def create
+ return unless session[:user_id]
+
+ logged_in_user_id = session[:user_id]
+ entry_id = params[:entry_id]
+ @vote = Vote.find_by_user_id_and_entry_id(logged_in_user_id, entry_id)
+ if @vote
+ Vote.delete(@vote.id)
+ @response = { success: true, total_votes: Vote.get_votes_number_for_entry(entry_id) }
+ else
+ @vote = Vote.new(user_id: logged_in_user_id, entry_id: entry_id)
+ if @vote.save
+ @response = { success: true, total_votes: Vote.get_votes_number_for_entry(entry_id) }
+ else
+ @response = { success: false }
+ end
+ end
+
+ respond_to do |format|
+ format.json { render :json => @response }
+ end
+ end
+
+
+private
+
+ def check_if_user_logged_in
+ # maybe
+ end
+
+
+end
@@ -0,0 +1,2 @@
+module VoteHelper
+end
View
@@ -1,6 +1,7 @@
class User < ActiveRecord::Base
has_many :authorizations
- has_many :entries
+ has_many :votes
+ has_many :entries
#validates :name, :presence => true
def add_provider(auth_hash)
@@ -9,5 +10,5 @@ def add_provider(auth_hash)
Authorization.create :user => self, :provider => auth_hash["provider"], :uid => auth_hash["uid"]
end
end
-
+
end
View
@@ -1,2 +1,9 @@
class Vote < ActiveRecord::Base
+ belongs_to :users
+ has_many :entries
+ validates_presence_of :user_id, :entry_id
+
+ def self.get_votes_number_for_entry(entry_id)
+ Vote.find_all_by_entry_id(entry_id).count
+ end
end
@@ -4,10 +4,14 @@
%title CodeNews
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
- = csrf_meta_tags
%meta{:name => "viewport",
:content => "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"}
-
+ %meta{ :charset => "utf-8" }/
+ %meta{ "http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1" }/
+ %meta{ :name => "description", :content => "" }/
+ %meta{ :name => "author", :content => "" }/
+ -#= javascript_include_tag 'modernizr.min'
+ = csrf_meta_tag
%body
.navbar
.navbar-inner
@@ -40,3 +44,9 @@
#container.container-fluid
= yield
#footer
+
+ :javascript
+ var _gaq=[["_setAccount","UA-31080926-1"],["_trackPageview"],["_trackPageLoadTime"]];
+ (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
+ g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
+ s.parentNode.insertBefore(g,s)}(document,"script"));
View
@@ -17,9 +17,3 @@ test:
database: db/test.sqlite3
pool: 5
timeout: 5000
-
-production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
View
@@ -9,6 +9,8 @@
root :to => 'entries#index'
+ get '/vote/:entry_id', :to => 'vote#create', :as => :vote
+
# Auth + Session management:
get '/login', :to => 'sessions#new', :as => :login
match '/auth/:provider', :to => 'sessions#create', :as => :auth
View
@@ -27,14 +27,14 @@
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
t.string "owner_avatar_url"
t.string "owner_login"
t.string "language"
t.integer "watchers"
t.integer "forks"
t.boolean "fork"
t.string "homepage_url"
- t.integer "user_id"
end
create_table "users", :force => true do |t|
View
@@ -5,15 +5,3 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-
-Entry.create(url: "https://github.com/BlueHotDog/CodeNews",
- desc: "Hackernews for Code :-)",
- name: "CodeNews")
-
-Entry.create(url: "https://github.com/twitter/bootstrap",
- desc: "HTML, CSS and JS toolkit from Twitter",
- name: "Bootstrap")
-
-Entry.create(url: "https://github.com/rails/rails",
- desc: "Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.",
- name: "Ruby on Rails")
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class VoteControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class VoteHelperTest < ActionView::TestCase
+end

0 comments on commit 61e8079

Please sign in to comment.