├── lib ├── tasks │ ├── .gitkeep │ └── cucumber.rake └── assets │ └── .gitkeep ├── app ├── mailers │ ├── .gitkeep │ └── user_mailer.rb ├── models │ ├── .gitkeep │ ├── spammer.rb │ ├── admin_auth.rb │ ├── data_set.rb │ ├── notification.rb │ ├── ability.rb │ ├── comment.rb │ ├── user.rb │ └── post.rb ├── helpers │ ├── admin_helper.rb │ ├── posts_helper.rb │ ├── comments_helper.rb │ ├── content_helper.rb │ └── application_helper.rb ├── views │ ├── comments │ │ ├── new.html.erb │ │ ├── edit.html.erb │ │ ├── _print.html.erb │ │ ├── index.html.erb │ │ ├── _form.html.erb │ │ ├── _show.html.erb │ │ └── show.html.erb │ ├── posts │ │ ├── edit.html.erb │ │ ├── new.html.erb │ │ ├── show.html.erb │ │ ├── index.html.erb │ │ ├── _form.html.erb │ │ ├── _preview.html.erb │ │ └── _print.html.erb │ ├── user_mailer │ │ ├── notify.text.erb │ │ ├── receive.text.erb │ │ ├── newsletter.text.erb │ │ └── newsletter.html.erb │ ├── admin │ │ ├── spam.html.erb │ │ └── mail.html.erb │ ├── content │ │ ├── stats.html.erb │ │ ├── ask.html.erb │ │ ├── new.html.erb │ │ ├── frontpage.html.erb │ │ ├── notifications.html.erb │ │ ├── new.rss.builder │ │ ├── ask.rss.builder │ │ ├── frontpage.rss.builder │ │ └── about.html.erb │ ├── devise │ │ ├── mailer │ │ │ ├── confirmation_instructions.html.erb │ │ │ ├── unlock_instructions.html.erb │ │ │ └── reset_password_instructions.html.erb │ │ ├── unlocks │ │ │ └── new.html.erb │ │ ├── passwords │ │ │ ├── new.html.erb │ │ │ └── edit.html.erb │ │ ├── confirmations │ │ │ └── new.html.erb │ │ ├── sessions │ │ │ └── new.html.erb │ │ ├── registrations │ │ │ ├── new.html.erb │ │ │ └── edit.html.erb │ │ └── _links.erb │ ├── users │ │ └── show.html.erb │ └── layouts │ │ └── application.html.erb ├── assets │ ├── images │ │ ├── info.png │ │ ├── rss.png │ │ ├── 57x57.png │ │ ├── email.png │ │ ├── rails.png │ │ ├── hackful.png │ │ └── email_alert.png │ ├── stylesheets │ │ ├── scaffolds.css.scss │ │ ├── admin.css.scss │ │ ├── posts.css.scss │ │ ├── comments.css.scss │ │ ├── content.css.scss │ │ ├── application.css │ │ └── layout.css.scss │ └── javascripts │ │ ├── voting.js │ │ ├── admin.js.coffee │ │ ├── comments.js.coffee │ │ ├── content.js.coffee │ │ ├── posts.js.coffee │ │ └── application.js └── controllers │ ├── filter_controller.rb │ ├── users_controller.rb │ ├── api │ ├── application_controller.rb │ ├── basic_api.rb │ └── v1 │ │ ├── users_controller.rb │ │ ├── sessions_controller.rb │ │ ├── comments_controller.rb │ │ └── posts_controller.rb │ ├── application_controller.rb │ ├── admin_controller.rb │ ├── content_controller.rb │ ├── comments_controller.rb │ └── posts_controller.rb ├── vendor ├── plugins │ └── .gitkeep └── assets │ └── stylesheets │ └── .gitkeep ├── .rspec ├── .gitignore ├── public ├── favicon.ico ├── robots.txt ├── 422.html ├── 404.html └── 500.html ├── config.ru ├── features ├── step_definitions │ ├── posts_steps.rb │ ├── devise_steps.rb │ └── shared_steps.rb ├── devise.feature ├── profile.feature ├── posts.feature └── support │ └── env.rb ├── db ├── migrate │ ├── 20120429110752_add_viewers_to_posts.rb │ ├── 20120224135606_create_admin_auths.rb │ ├── 20120629140850_create_spammers.rb │ ├── 20120219131606_add_authentication_token_to_users.rb │ ├── 20120208103944_create_notifications.rb │ ├── 20120128225717_create_posts.rb │ ├── 20120128225733_create_comments.rb │ ├── 20120307155241_create_data_sets.rb │ ├── 20120129132752_create_make_voteable_tables.rb │ ├── 20120226193229_create_delayed_jobs.rb │ └── 20120128225324_devise_create_users.rb ├── seeds.rb └── schema.rb ├── config ├── environment.rb ├── boot.rb ├── initializers │ ├── mime_types.rb │ ├── inflections.rb │ ├── backtrace_silencers.rb │ ├── session_store.rb │ ├── wrap_parameters.rb │ └── devise.rb ├── locales │ ├── en.yml │ └── devise.en.yml ├── database.yml ├── cucumber.yml ├── environments │ ├── development.rb │ ├── test.rb │ └── production.rb ├── application.rb └── routes.rb ├── spec ├── factories │ ├── posts.rb │ └── users.rb ├── support │ └── controller_macros.rb ├── controllers │ ├── admin_controller_spec.rb │ └── posts_controller_spec.rb └── spec_helper.rb ├── Rakefile ├── script ├── rails └── cucumber ├── LICENSE ├── Gemfile ├── Guardfile ├── README.md └── Gemfile.lock /lib/tasks/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/mailers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | --drb 3 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/helpers/admin_helper.rb: -------------------------------------------------------------------------------- 1 | module AdminHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/posts_helper.rb: -------------------------------------------------------------------------------- 1 | module PostsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/comments_helper.rb: -------------------------------------------------------------------------------- 1 | module CommentsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/content_helper.rb: -------------------------------------------------------------------------------- 1 | module ContentHelper 2 | end 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | config/initializers/secret_token.rb 3 | log/ 4 | tmp/ -------------------------------------------------------------------------------- /app/views/comments/new.html.erb: -------------------------------------------------------------------------------- 1 |

New comment

2 | 3 | <%= render 'form' %> 4 | -------------------------------------------------------------------------------- /app/views/posts/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing post

2 | 3 | <%= render 'form' %> 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /app/models/spammer.rb: -------------------------------------------------------------------------------- 1 | class Spammer < ActiveRecord::Base 2 | belongs_to :user 3 | end 4 | -------------------------------------------------------------------------------- /app/views/comments/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing comment

2 | 3 | <%= render 'form' %> 4 | -------------------------------------------------------------------------------- /app/models/admin_auth.rb: -------------------------------------------------------------------------------- 1 | class AdminAuth < ActiveRecord::Base 2 | belongs_to :user 3 | end 4 | -------------------------------------------------------------------------------- /app/assets/images/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/info.png -------------------------------------------------------------------------------- /app/assets/images/rss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/rss.png -------------------------------------------------------------------------------- /app/assets/images/57x57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/57x57.png -------------------------------------------------------------------------------- /app/assets/images/email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/email.png -------------------------------------------------------------------------------- /app/assets/images/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/rails.png -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | require ::File.expand_path('../config/environment', __FILE__) 2 | run Hackful::Application 3 | -------------------------------------------------------------------------------- /app/assets/images/hackful.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/hackful.png -------------------------------------------------------------------------------- /app/assets/images/email_alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8bitpal/hackful/HEAD/app/assets/images/email_alert.png -------------------------------------------------------------------------------- /app/views/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |

New post

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', posts_path %> 6 | -------------------------------------------------------------------------------- /app/views/user_mailer/notify.text.erb: -------------------------------------------------------------------------------- 1 | UserMailer#notify 2 | 3 | <%= @greeting %>, find me in app/views/app/views/user_mailer/notify.text.erb 4 | -------------------------------------------------------------------------------- /app/views/user_mailer/receive.text.erb: -------------------------------------------------------------------------------- 1 | UserMailer#receive 2 | 3 | <%= @greeting %>, find me in app/views/app/views/user_mailer/receive.text.erb 4 | -------------------------------------------------------------------------------- /features/step_definitions/posts_steps.rb: -------------------------------------------------------------------------------- 1 | When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, text| 2 | fill_in field, with: text 3 | end 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/scaffolds.css.scss: -------------------------------------------------------------------------------- 1 | a { 2 | color: #000; 3 | &:visited { 4 | color: #666; } 5 | &:hover { 6 | color: #000; } } 7 | -------------------------------------------------------------------------------- /app/views/user_mailer/newsletter.text.erb: -------------------------------------------------------------------------------- 1 | Hi <%= @user.name %>. 2 | 3 | <%= @text %> 4 | 5 | ------------ 6 | Hackful Europe 7 | http://hackful.com 8 | -------------------------------------------------------------------------------- /app/views/admin/spam.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_tag "/admin/save_spam_settings" do %> 2 | <%= text_area_tag :spammers %> 3 | <%= submit_tag "Submit" %> 4 | <% end %> -------------------------------------------------------------------------------- /app/assets/javascripts/voting.js: -------------------------------------------------------------------------------- 1 | function vote_up(id, type) { 2 | $.ajax('/'+type+'/'+id+'/vote_up'); 3 | $("#"+type+"_"+id).toggleClass("vote voted"); 4 | } 5 | -------------------------------------------------------------------------------- /app/views/content/stats.html.erb: -------------------------------------------------------------------------------- 1 |

Statistics

2 | 3 |

Comments per day

4 | 5 |

Posts per day

6 | 7 |

Average Comments per post

8 | 9 | -------------------------------------------------------------------------------- /app/views/user_mailer/newsletter.html.erb: -------------------------------------------------------------------------------- 1 | Hi <%= @user.name %>. 2 | 3 | <%= markdown(@text) %> 4 | 5 | ------------
6 | Hackful Europe
7 | http://hackful.com 8 | -------------------------------------------------------------------------------- /db/migrate/20120429110752_add_viewers_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddViewersToPosts < ActiveRecord::Migration 2 | def change 3 | add_column :posts, :viewers, :integer 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 | <%= render :partial => "posts/print", :locals => { post: @post } %> 2 | 3 | <%= render :partial => "comments/print", :locals => { commentable: @post } %> 4 | 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Hackful::Application.initialize! 6 | -------------------------------------------------------------------------------- /app/assets/stylesheets/admin.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Admin controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/posts.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Posts controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/models/data_set.rb: -------------------------------------------------------------------------------- 1 | class DataSet < ActiveRecord::Base 2 | #Initial table structure, could be changed in favor of more dynamic structure 3 | 4 | attr_accessible :contact_me, :user_id 5 | 6 | belongs_to :user 7 | end 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/comments.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Comments controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/content.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Content controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Set up gems listed in the Gemfile. 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 5 | 6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 7 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /app/models/notification.rb: -------------------------------------------------------------------------------- 1 | class Notification < ActiveRecord::Base 2 | belongs_to :alerted, :polymorphic => true 3 | belongs_to :alertable, :polymorphic => true 4 | 5 | attr_accessible :alertable_type, :alertable_id, :user_id, :alerted_type, :alerted_id 6 | end 7 | -------------------------------------------------------------------------------- /spec/factories/posts.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :post do 3 | title { FactoryGirl.generate :unique_user_name } 4 | text { Faker::Internet.email } 5 | link { "http://#{Faker::Internet.domain_name}/#{Faker::Internet.domain_word}" } 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/support/controller_macros.rb: -------------------------------------------------------------------------------- 1 | module ControllerMacros 2 | def login_user 3 | before(:each) do 4 | @request.env["devise.mapping"] = Devise.mappings[:user] 5 | user = Factory.create(:user) 6 | sign_in user 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/assets/javascripts/admin.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/comments.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/content.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/posts.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /app/views/admin/mail.html.erb: -------------------------------------------------------------------------------- 1 |

Mails

2 | 3 | <%= form_tag "/admin/send_newsletter" do %> 4 | Test run <%= check_box_tag "test" %>
5 | <%= text_field_tag :subject %>
6 | <%= text_area_tag :text %>

7 | <%= submit_tag "Send" %>
8 | <% end %> 9 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Hackful::Application.load_tasks 8 | -------------------------------------------------------------------------------- /app/views/devise/mailer/confirmation_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Welcome <%= @resource.email %>!

2 | 3 |

You can confirm your account email through the link below:

4 | 5 |

<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

6 | -------------------------------------------------------------------------------- /db/migrate/20120224135606_create_admin_auths.rb: -------------------------------------------------------------------------------- 1 | class CreateAdminAuths < ActiveRecord::Migration 2 | def change 3 | create_table :admin_auths do |t| 4 | t.integer :user_id 5 | t.string :resource 6 | t.string :action 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20120629140850_create_spammers.rb: -------------------------------------------------------------------------------- 1 | class CreateSpammers < ActiveRecord::Migration 2 | def change 3 | create_table :spammers do |t| 4 | t.references :user 5 | t.string :reason 6 | 7 | t.timestamps 8 | end 9 | add_index :spammers, :user_id 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20120219131606_add_authentication_token_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddAuthenticationTokenToUsers < ActiveRecord::Migration 2 | def change 3 | change_table :users do |t| 4 | t.string :authentication_token 5 | end 6 | 7 | add_index :users, :authentication_token, :unique => true 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /app/views/comments/_print.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <% commentable.comments.each do |comment| %> 3 | <%= render :partial => "comments/show", :locals => { comment: comment } %> 4 | <%= render :partial => "comments/print", :locals => { commentable: comment } if comment.comments.count > 0 %> 5 | <% end %> 6 |
7 | -------------------------------------------------------------------------------- /app/controllers/filter_controller.rb: -------------------------------------------------------------------------------- 1 | class FilterController < ApplicationController 2 | check_authorization 3 | load_and_authorize_resource 4 | 5 | rescue_from CanCan::AccessDenied do |exception| 6 | flash[:error] = exception.message 7 | session[:user_return_to] = request.url 8 | redirect_to new_user_session_path 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /script/cucumber: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 4 | if vendored_cucumber_bin 5 | load File.expand_path(vendored_cucumber_bin) 6 | else 7 | require 'rubygems' unless ENV['NO_RUBYGEMS'] 8 | require 'cucumber' 9 | load Cucumber::BINARY 10 | end 11 | -------------------------------------------------------------------------------- /app/views/devise/mailer/unlock_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

Your account has been locked due to an excessive amount of unsuccessful sign in attempts.

4 | 5 |

Click the link below to unlock your account:

6 | 7 |

<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>

8 | -------------------------------------------------------------------------------- /spec/factories/users.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | sequence :unique_user_name do |n| 3 | Faker::Internet.user_name.delete('^a-zA-Z') + "#{n}" 4 | end 5 | factory :user do 6 | name { FactoryGirl.generate :unique_user_name } 7 | email { Faker::Internet.email } 8 | password "testing" 9 | password_confirmation "testing" 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll automatically include all the stylesheets available in this directory 3 | * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 4 | * the top of the compiled file, but it's generally better to create a new file per style scope. 5 | *= require_self 6 | *= require_tree . 7 | */ -------------------------------------------------------------------------------- /db/migrate/20120208103944_create_notifications.rb: -------------------------------------------------------------------------------- 1 | class CreateNotifications < ActiveRecord::Migration 2 | def change 3 | create_table :notifications do |t| 4 | t.integer :user_id 5 | t.boolean :unread, :default => true 6 | t.references :alerted, :polymorphic => true 7 | t.references :alertable, :polymorphic => true 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20120128225717_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration 2 | def change 3 | create_table :posts do |t| 4 | t.integer :user_id 5 | t.string :title 6 | t.text :text 7 | t.text :link 8 | t.integer :up_votes, :null => false, :default => 0 9 | t.integer :down_votes, :null => false, :default => 0 10 | 11 | t.timestamps 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/views/devise/unlocks/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend unlock instructions

2 | 3 | <%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
<%= f.label :email %>
7 | <%= f.email_field :email %>
8 | 9 |
<%= f.submit "Resend unlock instructions" %>
10 | <% end %> 11 | 12 | <%= render "links" %> -------------------------------------------------------------------------------- /app/views/devise/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 |

Forgot your password?

2 | 3 | <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
<%= f.label :email %>
7 | <%= f.email_field :email %>
8 | 9 |
<%= f.submit "Send me reset password instructions" %>
10 | <% end %> 11 | 12 | <%= render "links" %> -------------------------------------------------------------------------------- /app/views/users/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= @user.name %>'s profile:

2 | 3 |

Submitted Stories: <%= @user.posts.count %>

4 | 5 | <% @posts.each do |post| %> 6 | <%= render partial: "posts/preview", locals: { post: post } %> 7 | <% end %> 8 | 9 | <%= link_to("< previous", "/?page="+(@page.to_i-1).to_s) if @page > 0 %>    <%= link_to("next >", "/?page="+(@page.to_i+1).to_s) if @posts.count > 19 %> -------------------------------------------------------------------------------- /db/migrate/20120128225733_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration 2 | def change 3 | create_table :comments do |t| 4 | t.integer :user_id 5 | t.text :text 6 | t.references :commentable, :polymorphic => true 7 | t.integer :up_votes, :null => false, :default => 0 8 | t.integer :down_votes, :null => false, :default => 0 9 | 10 | t.timestamps 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | #this works on Ubuntu Linux, change for your OS. 2 | development: 3 | adapter: mysql2 4 | encoding: utf8 5 | database: hackful 6 | username: root 7 | password: 8 | socket: /var/run/mysqld/mysqld.sock 9 | 10 | test: &test 11 | adapter: mysql2 12 | encoding: utf8 13 | database: hackful_test 14 | username: root 15 | password: 16 | socket: /var/run/mysqld/mysqld.sock 17 | 18 | cucumber: 19 | <<: *test 20 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | -------------------------------------------------------------------------------- /db/migrate/20120307155241_create_data_sets.rb: -------------------------------------------------------------------------------- 1 | class CreateDataSets < ActiveRecord::Migration 2 | def change 3 | create_table :data_sets do |t| 4 | t.integer :user_id 5 | t.boolean :contact_me, default: true 6 | t.string :twitter 7 | t.string :github 8 | t.string :linkedin 9 | t.string :url 10 | t.string :blog 11 | t.text :about_me 12 | 13 | t.timestamps 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /app/views/devise/confirmations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend confirmation instructions

2 | 3 | <%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
<%= f.label :email %>
7 | <%= f.email_field :email %>
8 | 9 |
<%= f.submit "Resend confirmation instructions" %>
10 | <% end %> 11 | 12 | <%= render "links" %> -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) 7 | # Mayor.create(:name => 'Emanuel', :city => cities.first) 8 | 9 | User.all.each do |user| 10 | DataSet.create(user_id: user.id) 11 | end -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Hackful::Application.config.session_store :cookie_store, :key => '_hackful_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Hackful::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /app/views/content/ask.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :head do %> 2 | <%= auto_discovery_link_tag :rss, "/ask.rss" %> 3 | <% end %> 4 | 5 | <% @posts.each do |post| %> 6 | <%= render partial: "posts/preview", locals: { post: post } if can? :see, post %> 7 | <% end %> 8 | 9 | <%= link_to("< previous", "/ask?page="+(@page.to_i-1).to_s) if @page > 1 %>    <%= link_to("next >", "/ask?page="+(@page.to_i+1).to_s) if @show_next_link %> 10 | -------------------------------------------------------------------------------- /app/views/content/new.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :head do %> 2 | <%= auto_discovery_link_tag :rss, "/new.rss" %> 3 | <% end %> 4 | 5 | <% @posts.each do |post| %> 6 | <%= render partial: "posts/preview", locals: { post: post } if can? :see, post %> 7 | <% end %> 8 | 9 | <%= link_to("< previous", "/new?page="+(@page.to_i-1).to_s) if @page > 1 %>    <%= link_to("next >", "/new?page="+(@page.to_i+1).to_s) if @show_next_link %> 10 | -------------------------------------------------------------------------------- /app/views/content/frontpage.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :head do %> 2 | <%= auto_discovery_link_tag :rss, "/frontpage.rss" %> 3 | <% end %> 4 | 5 | <% @posts.each do |post| %> 6 | <%= render partial: "posts/preview", locals: { post: post } if can? :see, post %> 7 | <% end %> 8 | 9 | <%= link_to("< previous", "/?page="+(@page.to_i-1).to_s) if @page > 1 %>    <%= link_to("next >", "/?page="+(@page.to_i+1).to_s) if @show_next_link %> 10 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | 3 | def show 4 | @user = User.find_by_name(params[:name].to_s) 5 | 6 | params[:page].nil? ? @page = 0 : @page = params[:page].to_i 7 | @posts = Post.find_by_sql ["SELECT * FROM posts WHERE user_id = #{@user.id} ORDER BY ((posts.up_votes - posts.down_votes) -1 )/POW((((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(posts.created_at)) / 3600 )+2), 1.5) DESC LIMIT ?, 20", (@page*20)] 8 | end 9 | 10 | end -------------------------------------------------------------------------------- /app/views/devise/mailer/reset_password_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

Someone has requested a link to change your password, and you can do this through the link below.

4 | 5 |

<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>

6 | 7 |

If you didn't request this, please ignore this email.

8 |

Your password won't change until you access the link above and create a new one.

9 | -------------------------------------------------------------------------------- /config/cucumber.yml: -------------------------------------------------------------------------------- 1 | <% 2 | rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" 3 | rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" 4 | std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip" 5 | %> 6 | default: --drb <%= std_opts %> features 7 | wip: --drb --tags @wip:3 --wip features 8 | rerun: --drb <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip 9 | -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into including all the files listed below. 2 | // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically 3 | // be included in the compiled file accessible from http://example.com/assets/application.js 4 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 5 | // the compiled file. 6 | // 7 | //= require jquery 8 | //= require jquery_ujs 9 | //= require_tree . 10 | 11 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | def comment_count(object) 3 | count = object.comments.count 4 | object.comments.each do |comment| 5 | count += comment_count(comment) 6 | end 7 | count 8 | end 9 | 10 | def markdown(text, *options) 11 | require 'rdiscount' 12 | 13 | text = sanitize(text) unless text.html_safe? || options.delete(:safe) 14 | (text.blank? ? "" : RDiscount.new(text, :filter_html, :autolink ).to_html.gsub(/(?\1').html_safe) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters :format => [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |

Sign in

2 | 3 | <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> 4 |
<%= f.label :email %>
5 | <%= f.email_field :email %>
6 | 7 |
<%= f.label :password %>
8 | <%= f.password_field :password %>
9 | 10 | <% if devise_mapping.rememberable? -%> 11 |
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
12 | <% end -%> 13 | 14 |
<%= f.submit "Sign in" %>
15 | <% end %> 16 | 17 | <%= render "links" %> -------------------------------------------------------------------------------- /app/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing posts

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <% @posts.each do |post| %> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <% end %> 21 |
UserText
<%= post.user_id %><%= post.text %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>
22 | 23 |
24 | 25 | <%= link_to 'New Post', new_post_path %> 26 | -------------------------------------------------------------------------------- /app/controllers/api/application_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::ApplicationController < ApplicationController 2 | include BasicApi 3 | 4 | respond_to :json 5 | 6 | before_filter :set_format 7 | 8 | rescue_from Exception do |exception| internal_server_error(exception) end 9 | rescue_from ActionController::UnknownAction, :with => :unknown_action 10 | rescue_from ActionController::RoutingError, :with => :route_not_found 11 | rescue_from ActiveRecord::RecordNotFound, with: :not_found 12 | rescue_from Api::BasicApi::NotLogedIn, with: :not_loged_in 13 | rescue_from Api::BasicApi::NoParameter, with: :no_parameter_found 14 | 15 | end -------------------------------------------------------------------------------- /app/views/devise/passwords/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Change your password

2 | 3 | <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %> 4 | <%= devise_error_messages! %> 5 | <%= f.hidden_field :reset_password_token %> 6 | 7 |
<%= f.label :password, "New password" %>
8 | <%= f.password_field :password %>
9 | 10 |
<%= f.label :password_confirmation, "Confirm new password" %>
11 | <%= f.password_field :password_confirmation %>
12 | 13 |
<%= f.submit "Change my password" %>
14 | <% end %> 15 | 16 | <%= render "links" %> -------------------------------------------------------------------------------- /app/views/comments/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing comments

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <% @comments.each do |comment| %> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <% end %> 21 |
UserText
<%= comment.user_id %><%= comment.text %><%= link_to 'Show', comment %><%= link_to 'Edit', edit_comment_path(comment) %><%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %>
22 | 23 |
24 | 25 | <%= link_to 'New Comment', new_comment_path %> 26 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | 4 | before_filter :meta_defaults 5 | 6 | def meta_defaults 7 | @title = "" 8 | @meta_keywords = "Europe, Startups, Entrepreneurs" 9 | @meta_description = "Hackful Europe is a place for European entrepreneurs to share demos, stories or ask questions." 10 | end 11 | 12 | def after_sign_out_path_for(resource) 13 | super 14 | end 15 | 16 | def after_sign_in_path_for(resource) 17 | super 18 | end 19 | 20 | def page_number(page = nil) 21 | page.nil? ? page = 1 : page = page.to_i 22 | return page 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Sign up

2 | 3 | <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
<%= f.label :name, "User Name" %>
7 | <%= f.text_field :name %>
8 | 9 |
<%= f.label :email %>
10 | <%= f.email_field :email %>
11 | 12 |
<%= f.label :password %>
13 | <%= f.password_field :password %>
14 | 15 |
<%= f.label :password_confirmation %>
16 | <%= f.password_field :password_confirmation %>
17 | 18 |
<%= f.submit "Sign up" %>
19 | <% end %> 20 | 21 | <%= render "links" %> 22 | -------------------------------------------------------------------------------- /features/step_definitions/devise_steps.rb: -------------------------------------------------------------------------------- 1 | When /^I fill in new user details$/ do 2 | within(".body") do 3 | fill_in 'User Name', with: 'pbjorklund' 4 | fill_in 'Email', with: 'p.bjorklund@gmail.com' 5 | fill_in 'Password', :with => 'password' 6 | fill_in 'Password confirmation', :with => 'password' 7 | end 8 | click_button "Sign up" 9 | end 10 | 11 | When /^I fill in my user details$/ do 12 | within(".body") do 13 | fill_in 'User Name', with: 'pbjorklund' 14 | fill_in 'Email', with: 'p.bjorklund@gmail.com' 15 | fill_in 'Password', :with => 'password' 16 | fill_in 'Password confirmation', :with => 'password' 17 | end 18 | click_button "Sign up" 19 | end 20 | -------------------------------------------------------------------------------- /app/models/ability.rb: -------------------------------------------------------------------------------- 1 | class Ability 2 | include CanCan::Ability 3 | 4 | def initialize(user) 5 | user ||= User.new 6 | can :see, Post do |post| 7 | if !post.user.nil? && post.user.is_spammer? && post.user.id != user.id 8 | false 9 | else 10 | true 11 | end 12 | end 13 | unless user.id.nil? 14 | can [:read, :create, :vote_up, :vote_down], [Post, Comment] 15 | can [:update, :destroy], [Post, Comment], :user_id => user.id 16 | 17 | user.admin_auths.each do |auth| 18 | (defined?(auth.resource.upcase) == "constant") ? (can auth.action.to_sym, auth.resource.constantize) : (can auth.action.to_sym, auth.resource.to_sym) 19 | end 20 | end 21 | can [:read], :all 22 | can :create, User 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /app/controllers/admin_controller.rb: -------------------------------------------------------------------------------- 1 | class AdminController < ApplicationController 2 | authorize_resource :class => false 3 | 4 | def mail 5 | 6 | end 7 | 8 | def send_newsletter 9 | if user_signed_in? 10 | unless params[:test] 11 | User.all.each do |user| 12 | UserMailer.delay.newsletter(user, params[:subject], params[:text]) 13 | end 14 | else 15 | UserMailer.delay.newsletter(current_user, params[:subject], params[:text]) 16 | end 17 | redirect_to "/admin/mail", notice: "Mail sent" 18 | end 19 | end 20 | 21 | def spam 22 | 23 | end 24 | 25 | def save_spam_settings 26 | @spammers = JSON(params[:spammers]) 27 | @spammers.each do |spammer| 28 | Spammer.create(user_id: User.find_by_name(spammer["name"]).id, reason: spammer["reason"]) 29 | end 30 | end 31 | 32 | end 33 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |

We've been notified about this issue and we'll take a look at it shortly.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /app/views/posts/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@post) do |f| %> 2 | <% if @post.errors.any? %> 3 |
4 |

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

5 | 6 | 11 |
12 | <% end %> 13 | 14 |
15 | <%= f.label :title %>
16 | <%= f.text_field :title %> 17 |
18 | 19 |
20 | <%= f.label :text %>
21 | <%= f.text_area :text %> 22 |
23 | 24 | 28 |
29 | <%= f.submit %> 30 |
31 | <% end %> 32 | -------------------------------------------------------------------------------- /features/devise.feature: -------------------------------------------------------------------------------- 1 | Feature: User authentication 2 | 3 | As a user 4 | To submit, vote and post news items 5 | I want to be able to sign in 6 | 7 | Scenario: Sign up 8 | #Issue : 9 | #Given I am not authenticated 10 | Given I am on the startpage 11 | When I click "Sign in" 12 | And I click "Sign up" 13 | And I fill in new user details 14 | Then I should see "Welcome! You have signed up successfully." 15 | 16 | Scenario: Sign in 17 | Given I am a new authenticated user 18 | Then I should see "Signed in" 19 | 20 | #Issue : 21 | #Scenario: Sign out 22 | # Given I am a new authenticated user 23 | # When I click "Sign out" 24 | # Then I should see "Signed out successfully." 25 | 26 | Scenario: Sign out 27 | Given I am a new authenticated user 28 | When I click "Sign out" 29 | Then I should see "Signed out successfully." 30 | 31 | -------------------------------------------------------------------------------- /app/views/content/notifications.html.erb: -------------------------------------------------------------------------------- 1 |

Notifications

2 | <% @new_notifications.each do |notification| %> 3 |
4 |

<%= link_to(notification.alertable.user.name, user_path(notification.alertable.user.name)) %> replied to your <%= link_to notification.alerted.class.name, notification.alerted %>

5 | <%= render :partial => "comments/show", :locals => { comment: notification.alertable } %> 6 |
7 | <% end %> 8 | <% @old_notifications.each do |notification| %> 9 |
10 |

<%= link_to(notification.alertable.user.name, user_path(notification.alertable.user.name)) %> replied to your <%= link_to notification.alerted.class.name, notification.alerted %>

11 | <%= render :partial => "comments/show", :locals => { comment: notification.alertable } %> 12 |
13 | <% end %> 14 | <% @new_notifications.update_all(:unread => false) %> 15 | -------------------------------------------------------------------------------- /db/migrate/20120129132752_create_make_voteable_tables.rb: -------------------------------------------------------------------------------- 1 | class CreateMakeVoteableTables < ActiveRecord::Migration 2 | def self.up 3 | create_table :votings do |t| 4 | t.string :voteable_type 5 | t.integer :voteable_id 6 | t.string :voter_type 7 | t.integer :voter_id 8 | t.boolean :up_vote, :null => false 9 | 10 | t.timestamps 11 | end 12 | 13 | add_index :votings, [:voteable_type, :voteable_id] 14 | add_index :votings, [:voter_type, :voter_id] 15 | add_index :votings, [:voteable_type, :voteable_id, :voter_type, :voter_id], :name => "unique_voters", :unique => true 16 | end 17 | 18 | def self.down 19 | remove_index :votings, :column => [:voteable_type, :voteable_id] 20 | remove_index :votings, :column => [:voter_type, :voter_id] 21 | remove_index :votings, :name => "unique_voters" 22 | 23 | drop_table :votings 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/views/content/new.rss.builder: -------------------------------------------------------------------------------- 1 | xml.instruct! :xml, :version => "1.0" 2 | xml.rss :version => "2.0", "xmlns:he" => 'http://hackful.com/rss/hackful' do 3 | xml.channel do 4 | xml.title "Hackful Europe - New posts" 5 | xml.description "A place for European entrepreneurs to share demos, stories or ask questions." 6 | xml.link "http://hackful.com" 7 | 8 | for post in @posts 9 | unless post.user.is_spammer? 10 | xml.item do 11 | xml.title post.title 12 | xml.description markdown(post.text) 13 | xml.pubDate post.created_at.to_s(:rfc822) 14 | xml.link post.link 15 | xml.comments post_url(post) 16 | xml.guid post_url(post) 17 | xml.he :submitter, (post.user.nil? ? "[Deleted]" : post.user.name) 18 | xml.he :points, post.votes 19 | xml.he :commentcount, comment_count(post) 20 | end 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/views/content/ask.rss.builder: -------------------------------------------------------------------------------- 1 | xml.instruct! :xml, :version => "1.0" 2 | xml.rss :version => "2.0", "xmlns:he" => 'http://hackful.com/rss/hackful' do 3 | xml.channel do 4 | xml.title "Hackful Europe - Ask posts" 5 | xml.description "A place for European entrepreneurs to share demos, stories or ask questions." 6 | xml.link "http://hackful.com" 7 | 8 | for post in @posts 9 | unless post.user.is_spammer? 10 | xml.item do 11 | xml.title post.title 12 | xml.description markdown(post.text) 13 | xml.pubDate post.created_at.to_s(:rfc822) 14 | xml.link post_url(post) 15 | xml.comments post_url(post) 16 | xml.guid post_url(post) 17 | xml.he :submitter, (post.user.nil? ? "[Deleted]" : post.user.name) 18 | xml.he :points, post.votes 19 | xml.he :commentcount, comment_count(post) 20 | end 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/views/content/frontpage.rss.builder: -------------------------------------------------------------------------------- 1 | xml.instruct! :xml, :version => "1.0" 2 | xml.rss :version => "2.0", "xmlns:he" => 'http://hackful.com/rss/hackful' do 3 | xml.channel do 4 | xml.title "Hackful Europe - Top posts" 5 | xml.description "A place for European entrepreneurs to share demos, stories or ask questions." 6 | xml.link "http://hackful.com" 7 | 8 | for post in @posts 9 | unless post.user.is_spammer? 10 | xml.item do 11 | xml.title post.title 12 | xml.description markdown(post.text) 13 | xml.pubDate post.created_at.to_s(:rfc822) 14 | xml.link post.link 15 | xml.comments post_url(post) 16 | xml.guid post_url(post) 17 | xml.he :submitter, (post.user.nil? ? "[Deleted]" : post.user.name) 18 | xml.he :points, post.votes 19 | xml.he :commentcount, comment_count(post) 20 | end 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/views/comments/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@comment) do |f| %> 2 | <% if @comment.errors.any? %> 3 |
4 |

<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:

5 | 6 | 11 |
12 | <% end %> 13 | 14 |
15 | <%= f.text_area :text, :rows => 5 %> 16 |
17 |
18 | <% if defined? commentable_id %> 19 | <%= f.hidden_field :commentable_id, :value => commentable_id %> 20 | <%= f.hidden_field :commentable_type, :value => commentable_type %> 21 | <% end %> 22 | 23 | <% if @comment.errors.any? %> 24 | <%= f.hidden_field :commentable_id %> 25 | <%= f.hidden_field :commentable_type %> 26 | <% end %> 27 |
28 |
29 | <%= f.submit( :value => "Post Comment", :class => "blue button" ) %> 30 |
31 | <% end %> 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Elias Haase 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /features/profile.feature: -------------------------------------------------------------------------------- 1 | Feature: Updating user profile 2 | 3 | To share information about me or update my settings 4 | As a user 5 | I want to be able to update my settings 6 | 7 | Scenario: Changing user-name 8 | Given I am a new authenticated user 9 | When I visit "/users/edit" 10 | And I fill in my user details without submitting 11 | And I fill in "User Name" with "newtestname" 12 | And I click the button "Update" 13 | Then I should see "You updated your account successfully." 14 | 15 | Scenario: Changing password 16 | Given I am a new authenticated user 17 | When I visit "/users/edit" 18 | And I fill in my user details without submitting 19 | And I fill in "Password" with "newtestpassword" 20 | And I fill in "Password confirmation" with "newtestpassword" 21 | And I click the button "Update" 22 | Then I should see "You updated your account successfully." 23 | 24 | Scenario: Deleting account 25 | Given I am a new authenticated user 26 | When I visit "/users/edit" 27 | And I click "Cancel my account" 28 | Then I should see "Bye! Your account was successfully cancelled. We hope to see you again soon." 29 | -------------------------------------------------------------------------------- /app/views/devise/_links.erb: -------------------------------------------------------------------------------- 1 | <%- if controller_name != 'sessions' %> 2 | <%= link_to "Sign in", new_session_path(resource_name) %>
3 | <% end -%> 4 | 5 | <%- if devise_mapping.registerable? && controller_name != 'registrations' %> 6 | <%= link_to "Sign up", new_registration_path(resource_name) %>
7 | <% end -%> 8 | 9 | <%- if devise_mapping.recoverable? && controller_name != 'passwords' %> 10 | <%= link_to "Forgot your password?", new_password_path(resource_name) %>
11 | <% end -%> 12 | 13 | <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> 14 | <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
15 | <% end -%> 16 | 17 | <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> 18 | <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
19 | <% end -%> 20 | 21 | <%- if devise_mapping.omniauthable? %> 22 | <%- resource_class.omniauth_providers.each do |provider| %> 23 | <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
24 | <% end -%> 25 | <% end -%> -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Hackful::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Do not compress assets 26 | config.assets.compress = false 27 | 28 | # Expands the lines which load the assets 29 | config.assets.debug = true 30 | end 31 | -------------------------------------------------------------------------------- /app/mailers/user_mailer.rb: -------------------------------------------------------------------------------- 1 | class UserMailer < ActionMailer::Base 2 | helper :application 3 | 4 | default from: "mail@hackful.com" 5 | 6 | def receive(email) 7 | commentable_string = email.subject.scan(/\(\w{1,} #\d*\)/mi)[0] 8 | commentable_type = commentable_string.scan(/[a-zA-Z]+/mi)[0] 9 | commentable_id = commentable_string.scan(/[0-9]{1,}/)[0].to_i 10 | text = email.body.decoded.gsub(/(^>.*)|((\w*\s*)[0-9]{1,}.*:$)/mi, "") 11 | Comment.new(commentable_type: commentable_type, commentable_id: commentable_id, text: text, user_id: User.find_by_email(email.from.first).id).save! unless User.find_by_email(email.from.first).nil? 12 | end 13 | 14 | # Subject can be set in your I18n file at config/locales/en.yml 15 | # with the following lookup: 16 | # 17 | # en.user_mailer.newsletter.subject 18 | # 19 | def newsletter(user, subject, text) 20 | @user = user 21 | @text = text 22 | 23 | mail(to: user.email, subject: subject) 24 | end 25 | 26 | # Subject can be set in your I18n file at config/locales/en.yml 27 | # with the following lookup: 28 | # 29 | # en.user_mailer.notify.subject 30 | # 31 | def notify 32 | @greeting = "Hi" 33 | 34 | mail to: "to@example.org" 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | class Comment < ActiveRecord::Base 2 | include ActionView::Helpers::SanitizeHelper 3 | 4 | after_create { |comment| Notification.new(:user_id => comment.commentable.user_id, :alerted_type => comment.commentable.class.name, :alerted_id => comment.commentable.id, :alertable_type => comment.class.name, :alertable_id => comment.id ).save! } 5 | 6 | belongs_to :commentable, :polymorphic => true 7 | belongs_to :user 8 | 9 | attr_accessible :commentable_type, :commentable_id, :text, :user_id 10 | 11 | has_many :comments, :as => :commentable 12 | 13 | make_voteable 14 | 15 | validates :text, :length => { :minimum => 2 }, :allow_blank => false 16 | 17 | def root 18 | commentable = self.commentable 19 | while commentable.class == "Comment" 20 | commentable = commentable.commentable 21 | end 22 | commentable 23 | end 24 | 25 | def as_json(options = {}) 26 | super( 27 | :include => {:user => {:only => [:id, :name]}}, 28 | :except => [:user_id, :down_votes, :commentable_type], 29 | :methods => :voted 30 | ) 31 | end 32 | 33 | def voted 34 | current_user = User.current_user 35 | unless current_user.blank? 36 | current_user.voted?(self) 37 | else 38 | false 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /app/views/posts/_preview.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <% if user_signed_in? %> 3 | <% if current_user.voted?(post) %> 4 |
5 | <% else %> 6 |
7 | <% end %> 8 | <%= link_to "▲".html_safe, "#", :onClick => "vote_up("+post.id.to_s+", 'posts'); return false" %> 9 | <% else %> 10 |
11 | <%= link_to "▲".html_safe, new_user_session_path %> 12 | <% end %> 13 |
14 |
15 |
16 | <%= (post.link.nil? or post.link.empty?) ? (link_to post.title, post) : (link_to post.title, post.link) %> 17 | <% uri = URI.parse(post.link) %> 18 | <% unless post.link.nil? or post.link.empty? or uri.host.nil? %> 19 | <%= link_to("("+uri.host.gsub("www.","")+")", "http://"+uri.host) %> 20 | <% end %> 21 |
22 |
<%= pluralize(post.votes, "point") %> by <%= (post.user.nil? ? "[Deleted]" : link_to(post.user.name, user_path(post.user.name))) %> <%= time_ago_in_words(post.created_at) %> ago | <%= link_to(pluralize(comment_count(post), "comment"), post) %> 23 |
24 |
25 |
26 | -------------------------------------------------------------------------------- /app/controllers/api/basic_api.rb: -------------------------------------------------------------------------------- 1 | require 'action_controller' 2 | module Api::BasicApi 3 | class NotLogedIn < StandardError; end 4 | class NoParameter < StandardError; end 5 | class NoPermission < StandardError; end 6 | 7 | def not_found 8 | head :not_found 9 | end 10 | 11 | def internal_server_error(exception = nil) 12 | error = { 13 | :error => "internal server error", 14 | :exception => exception.message, 15 | :stacktrace => exception.backtrace 16 | } 17 | render :json => error, :status => 500 18 | end 19 | 20 | def no_parameter_found 21 | render :json => failure_message("Missing parameters"), :status => 422 22 | end 23 | 24 | def not_loged_in 25 | render :json => failure_message("Please login"), :status => 401 26 | end 27 | 28 | def success_message(message, info = nil) 29 | json = {:success => true, :message => message} 30 | json.merge! info unless info.nil? 31 | return json 32 | end 33 | 34 | def failure_message(message, errors = nil) 35 | json = {:success => false, :message => message} 36 | json.merge! errors unless errors.nil? 37 | return json 38 | end 39 | 40 | def check_login 41 | raise NotLogedIn unless user_signed_in? 42 | end 43 | 44 | private 45 | def set_format 46 | request.format = 'json' 47 | end 48 | end -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | source 'http://gemcutter.org' 3 | 4 | gem 'rails', '3.1.10' 5 | 6 | gem 'sqlite3' 7 | gem 'json', '>=1.7.7' 8 | 9 | group :assets do 10 | gem 'sass-rails' 11 | gem 'coffee-rails' 12 | gem 'uglifier', '>= 1.0.3' 13 | end 14 | 15 | group :test, :development do 16 | gem 'cucumber-rails' 17 | gem 'database_cleaner' 18 | gem 'rspec-rails' 19 | gem 'cucumber-rails', require: false 20 | gem "factory_girl_rails" 21 | gem 'capybara' 22 | gem "capybara-webkit" 23 | gem 'fakeweb' 24 | gem "launchy" 25 | gem 'database_cleaner', :group => :test 26 | gem 'faker' 27 | gem 'pry' 28 | gem 'rest-client' 29 | 30 | if RUBY_PLATFORM.downcase.include?("darwin") 31 | gem "guard" 32 | gem "guard-rspec" 33 | gem "guard-cucumber" 34 | gem "guard-bundler" 35 | gem "guard-spork" 36 | gem 'spork' 37 | gem 'rb-fsevent' 38 | gem 'growl' # also install growlnotify from the Extras/growlnotify/growlnotify.pkg in Growl disk image 39 | end 40 | end 41 | 42 | gem 'execjs' 43 | gem 'therubyracer' 44 | gem 'devise' 45 | gem 'nested_form', :git => 'git://github.com/fxposter/nested_form.git' 46 | gem 'jquery-rails' 47 | gem 'cancan' 48 | gem 'make_voteable' 49 | gem 'mysql2' 50 | gem 'rails_autolink' 51 | gem 'rdiscount' 52 | gem 'delayed_job' 53 | gem 'delayed_job_active_record' 54 | gem 'whenever' -------------------------------------------------------------------------------- /app/views/devise/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Edit <%= resource_name.to_s.humanize %>

2 | 3 | <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
<%= f.label :name, "User Name" %>
7 | <%= f.text_field :name %>
8 | 9 |
<%= f.label :email %>
10 | <%= f.email_field :email %>
11 | 12 |
<%= f.label :password %> (leave blank if you don't want to change it)
13 | <%= f.password_field :password %>
14 | 15 |
<%= f.label :password_confirmation %>
16 | <%= f.password_field :password_confirmation %>
17 | 18 |
<%= f.label :current_password %> (we need your current password to confirm your changes)
19 | <%= f.password_field :current_password %>
20 | 21 |
<%= f.fields_for :data_set do |data_set_form| %> 22 | <%= data_set_form.label :contact_me, "Send email notifications" %> 23 | <%= data_set_form.check_box :contact_me %> 24 | <% end %>
25 | 26 |
<%= f.submit "Update" %>
27 | <% end %> 28 | 29 |

Cancel my account

30 | 31 |

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.

32 | 33 | <%= link_to "Back", :back %> 34 | -------------------------------------------------------------------------------- /db/migrate/20120226193229_create_delayed_jobs.rb: -------------------------------------------------------------------------------- 1 | class CreateDelayedJobs < ActiveRecord::Migration 2 | def self.up 3 | create_table :delayed_jobs, :force => true do |table| 4 | table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue 5 | table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually. 6 | table.text :handler # YAML-encoded string of the object that will do work 7 | table.text :last_error # reason for last failure (See Note below) 8 | table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. 9 | table.datetime :locked_at # Set when a client is working on this object 10 | table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) 11 | table.string :locked_by # Who is working on this object (if locked) 12 | table.string :queue # The name of the queue this job is in 13 | table.timestamps 14 | end 15 | 16 | add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' 17 | end 18 | 19 | def self.down 20 | drop_table :delayed_jobs 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/controllers/content_controller.rb: -------------------------------------------------------------------------------- 1 | class ContentController < ApplicationController 2 | def frontpage 3 | @page = page_number(params[:page]) 4 | @posts = Post.find_frontpage(@page) 5 | @show_next_link = (Post.find_frontpage(@page+1).length > 0) 6 | 7 | respond_to do |f| 8 | f.html 9 | f.rss { render :layout => false } 10 | end 11 | end 12 | 13 | def new 14 | @page = page_number(params[:page]) 15 | @posts = Post.find_new(@page) 16 | @show_next_link = (Post.find_frontpage(@page+1).length > 0) 17 | 18 | respond_to do |f| 19 | f.html 20 | f.rss { render :layout => false } 21 | end 22 | end 23 | 24 | def ask 25 | @page = page_number(params[:page]) 26 | @posts = Post.find_ask(@page) 27 | @show_next_link = (Post.find_frontpage(@page+1).length > 0) 28 | 29 | respond_to do |f| 30 | f.html 31 | f.rss { render :layout => false } 32 | end 33 | end 34 | 35 | def about 36 | respond_to do |f| 37 | f.html 38 | end 39 | end 40 | 41 | def notifications 42 | notifications = current_user.all_notifications 43 | @new_notifications = notifications[:new_notifications] 44 | @old_notifications = notifications[:old_notifications] 45 | @comment = Comment.new 46 | respond_to do |f| 47 | f.html 48 | end 49 | end 50 | 51 | def hackfulthon 52 | render layout: false 53 | end 54 | 55 | end 56 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | # Include default devise modules. Others available are: 3 | # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable 4 | devise :database_authenticatable, :registerable, 5 | :recoverable, :rememberable, :trackable, :validatable, 6 | :token_authenticatable 7 | 8 | cattr_accessor :current_user 9 | 10 | # Setup accessible (or protected) attributes for your model 11 | attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :data_set_attributes 12 | 13 | has_many :votes, :as => :voteable 14 | has_many :comments 15 | has_many :posts 16 | has_many :notifications, :order => "created_at DESC" 17 | has_many :admin_auths 18 | 19 | has_one :data_set 20 | accepts_nested_attributes_for :data_set 21 | 22 | validates_uniqueness_of :name 23 | validates_format_of :name, :with => /\A[a-zA-Z0-9]+\z/i, 24 | :message => "can only contain letters and numbers." 25 | 26 | make_voter 27 | 28 | def is_spammer? 29 | !Spammer.find_by_user_id(self.id).nil? 30 | end 31 | 32 | def all_notifications 33 | { 34 | :new_notifications => self.notifications.where(:unread => true), 35 | :old_notifications => self.notifications.find(:all, 36 | :conditions => { :unread => false }, :limit => 20) 37 | } 38 | end 39 | end 40 | 41 | -------------------------------------------------------------------------------- /features/step_definitions/shared_steps.rb: -------------------------------------------------------------------------------- 1 | Given /^I am on the startpage$/ do 2 | visit "/" 3 | end 4 | 5 | Given /^I am a new authenticated user$/ do 6 | email = 'testing@man.net' 7 | password = 'secretpass' 8 | @user = FactoryGirl.create(:user, email: email, password: password, password_confirmation: password) 9 | 10 | visit '/users/sign_in' 11 | fill_in "user_email", :with=>email 12 | fill_in "user_password", :with=>password 13 | click_button "Sign in" 14 | end 15 | 16 | Given /^I am not authenticated$/ do 17 | visit('/users/sign_out') 18 | end 19 | 20 | Given /^I am on the page for a submitted post$/ do 21 | post = @user.posts.create(FactoryGirl.build(:post).attributes) 22 | visit "/posts/#{post.id}" 23 | end 24 | 25 | 26 | Given /^the user has deleted his account$/ do 27 | User.delete_all 28 | end 29 | 30 | When /^I click "([^"]*)"$/ do |link| 31 | click_link link 32 | end 33 | 34 | When /^I click the button "([^"]*)"$/ do |button| 35 | click_button button 36 | end 37 | 38 | Then /^I should see "([^"]*)"$/ do |text| 39 | page.should have_content(text) 40 | end 41 | 42 | When /^I visit "([^"]*)"$/ do |page| 43 | visit page 44 | end 45 | 46 | When /^I fill in my user details without submitting$/ do 47 | fill_in 'User Name', with: 'pbjorklund' 48 | fill_in 'Email', with: 'p.bjorklund@gmail.com' 49 | fill_in 'Current password', :with => 'secretpass' 50 | end 51 | -------------------------------------------------------------------------------- /features/posts.feature: -------------------------------------------------------------------------------- 1 | Feature: Submitting news items 2 | 3 | To share news about startup related news in europe 4 | As a user 5 | I want to be able to submit stories 6 | 7 | Scenario: Submitting 8 | Given I am a new authenticated user 9 | When I click "submit" 10 | And I fill in "Title" with "Hackful integration tests pull request submitted" 11 | And I fill in "Text" with "Check out the github issues list to see the pull request" 12 | And I fill in "Link" with "https://github.com/8bitpal/hackful/issues" 13 | And I click the button "Create Post" 14 | Then I should see "Post was successfully created." 15 | 16 | Scenario: Editing 17 | Given I am a new authenticated user 18 | And I am on the page for a submitted post 19 | When I click "Edit" 20 | And I fill in "Title" with "Hackful integration tests pull request declined" 21 | And I fill in "Text" with "See this example of how not to submit pull requests" 22 | And I fill in "Link" with "https://github.com/8bitpal/hackful/pull/41" 23 | And I click the button "Update Post" 24 | Then I should see "Post was successfully updated." 25 | 26 | Scenario: Editing a post where the user has deleted his account 27 | Given I am a new authenticated user 28 | And I am on the page for a submitted post 29 | And the user has deleted his account 30 | When I am on the startpage 31 | Then I should see "[Deleted]" 32 | -------------------------------------------------------------------------------- /app/views/comments/_show.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <% if user_signed_in? %> 3 | <% if current_user.voted?(comment) %> 4 |
5 | <% else %> 6 |
7 | <% end %> 8 | <%= link_to "▲".html_safe, "#", :onClick => "vote_up("+comment.id.to_s+", 'comments'); return false" %> 9 | <% else %> 10 |
11 | <%= link_to "▲".html_safe, new_user_session_path %> 12 | <% end %> 13 |
14 |
15 | <%= markdown(comment.text) %> 16 |
17 | <%= pluralize(comment.votes, "point") %> by <%= (comment.user.nil? ? "[Deleted]" : link_to(comment.user.name, user_path(comment.user.name))) %> <%= time_ago_in_words(comment.created_at) %> ago   18 | <% if can? :update, comment %> 19 | <%= link_to 'Edit', edit_comment_path(comment) %> 20 | <% end %> 21 |
22 | <%= link_to('reply', "#", "onClick" => "$('#comment_form_#{comment.id.to_s}').slideToggle(); return false", class: "comment_reply") if can? :create, Comment %>
23 |
24 | 27 |
28 | -------------------------------------------------------------------------------- /app/views/content/about.html.erb: -------------------------------------------------------------------------------- 1 |

Hackful Europe

2 | A place for European entrepreneurs to share demos, stories or ask questions.

3 | developed by <%= link_to "@8bitpal", "https://twitter.com/8bitpal" %>
4 | idea by <%= link_to "@rayhanrafiq", "https://twitter.com/rayhanrafiq" %> and <%= link_to "@mattslight", "https://twitter.com/mattslight" %>
5 | hosting donated by <%= link_to "incite ict", "http://www.incite-ict.com/" %>

6 | 7 | Born out of the mailing list of a group called Open Coffee London, an
8 | amazing community of entrepreneurs helping each other everyday.

9 | 10 | We saw how open HackerNews is and thought we should give our European
11 | community more chance to flourish.

12 | 13 | Our next steps include 14 |
    15 |
  • Local Event Calendars
    Both local and major European events, localised based on user settings.
  • 16 |
  • Local Angel Directories
    Localised based on user settings.
  • 17 |
  • More sharing, subscription and data exchange options
    Opt-in digest emails, JSON API and more.
  • 18 |
19 |
20 | The source code for this platform is available on <%= link_to "Github", "https://github.com/8bitpal/hackful" %>.
21 | Contributions, bug reports and reasonable feature requests are welcome.

22 | 23 | We also hang out on IRC - #Hackful-Europe @ irc.freenode.net 24 | 25 |

26 | -------------------------------------------------------------------------------- /app/views/comments/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <% commentable.comments.each do |comment| %> 3 |
' 4 | <% if user_signed_in? %> 5 | <% if current_user.voted?(post) %> 6 |
7 | <% else %> 8 |
9 | <% end %> 10 | <%= link_to "▲".html_safe, "#", :onClick => "vote_up("+post.id.to_s+", 'posts'); return false" %> 11 | <% else %> 12 |
13 | <%= link_to "▲".html_safe, new_user_session_path %> 14 | <% end %> 15 |
16 |
17 | simple_format(auto_link(comment.text)) 18 |
<%= pluralize(comment.votes, "point") %> by <%= link_to(comment.user.name, user_path(comment.user.name)) %> <%= time_ago_in_words(comment.created_at) %> ago   19 | if can? :update, comment 20 | link_to 'Edit', edit_comment_path(comment) 21 | end 22 |
23 | <%= link_to('reply', "#", "onClick" => "$('#comment_form_#{comment.id.to_s}').slideToggle(); return false", class: "comment_reply") if can? :create, Comment %> 24 |
25 |
26 | 29 |
30 | <%= render :partial "comments/print", comment: comment if comment.comments.count > 0 %> 31 | end 32 |
" 33 | -------------------------------------------------------------------------------- /app/views/posts/_print.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <% if user_signed_in? %> 3 | <% if current_user.voted?(post) %> 4 |
5 | <% else %> 6 |
7 | <% end %> 8 | <%= link_to "▲".html_safe, "#", :onClick => "vote_up("+post.id.to_s+", 'posts'); return false" %> 9 | <% else %> 10 |
11 | <%= link_to "▲".html_safe, new_user_session_path %> 12 | <% end %> 13 |
14 |
15 | <%= (post.link.nil? or post.link.empty?) ? (link_to(post.title, post)) : (link_to(post.title, post.link)) %> 16 | <% uri = URI.parse(post.link) %> 17 | <% unless post.link.nil? or post.link.empty? or uri.host.nil? %> 18 | <%= link_to("("+uri.host.gsub("www.","")+")", "http://"+uri.host) %> 19 | <% end %> 20 |

<%= markdown(post.text) %>

21 |
<%= pluralize(post.votes, "point") %> by <%= (post.user.nil? ? "[Deleted]" : link_to(post.user.name, user_path(post.user.name))) %> <%= time_ago_in_words(post.created_at) %> ago | <%= link_to(pluralize(comment_count(post), "comment"), post) %> 22 | <% if can? :update, post %> 23 | <%= link_to 'Edit', edit_post_path(post) %> 24 | <% end %> 25 |
26 | <% if can? :create, Comment %> 27 |
28 | <%= render :partial => 'comments/form', :locals => { :commentable_type => "Post", :commentable_id => post.id } %> 29 |
30 | <% end %> 31 |
32 |
33 | -------------------------------------------------------------------------------- /spec/controllers/admin_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe AdminController do 4 | login_user 5 | context "logged in as user" do 6 | 7 | describe "GET 'mail'" do 8 | it "requires that the user is admin" do 9 | expect { get 'mail' }.to raise_error(CanCan::AccessDenied) 10 | #TODO response.should redirect_to root_path 11 | end 12 | end 13 | 14 | describe "POST 'send_newsletter'" do 15 | it "requires that the user is admin" do 16 | expect { post 'send_newsletter' }.to raise_error(CanCan::AccessDenied) 17 | end 18 | end 19 | end 20 | 21 | context "logged in as admin" do 22 | before(:each) do 23 | [{ resource: :all, action: :mail }, { resource: :all, action: :send_newsletter }].each do |hash| 24 | controller.current_user.admin_auths.create hash 25 | end 26 | end 27 | 28 | describe "GET 'mail'" do 29 | it "returns HTTP success" do 30 | get :mail 31 | response.should be_success 32 | end 33 | end 34 | 35 | describe "POST 'send_newsletter'" do 36 | before(:each) do 37 | controller.stub(:user_signed_in?).and_return(true) 38 | mailer = mock_model("Mailer", newsletter: nil) 39 | UserMailer.stub(:delay).and_return(mailer) 40 | mailer.should_receive(:newsletter).once 41 | 42 | end 43 | 44 | #TODO refactor the implementation code for this. It's strange 45 | it "returns HTTP success if the user is signed in" do 46 | controller.stub(:user_signed_in?).and_return(true) 47 | 48 | post :send_newsletter, subject: "Test", text: "Texttest" 49 | response.should redirect_to admin_mail_path 50 | flash[:notice].should == "Mail sent" 51 | end 52 | end 53 | end 54 | end 55 | 56 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Hackful::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Use SQL instead of Active Record's schema dumper when creating the test database. 33 | # This is necessary if your schema can't be completely dumped by the schema dumper, 34 | # like if you have constraints or database-specific column types 35 | # config.active_record.schema_format = :sql 36 | 37 | # Print deprecation notices to the stderr 38 | config.active_support.deprecation = :stderr 39 | end 40 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'spork' 3 | #uncomment the following line to use spork with the debugger 4 | #require 'spork/ext/ruby-debug' 5 | 6 | Spork.prefork do 7 | # Loading more in this block will cause your tests to run faster. However, 8 | # if you change any configuration or code from libraries loaded here, you'll 9 | # need to restart spork for it take effect. 10 | 11 | ENV["RAILS_ENV"] ||= 'test' 12 | require File.expand_path("../../config/environment", __FILE__) 13 | require 'rspec/rails' 14 | require 'rspec/autorun' 15 | 16 | # Requires supporting ruby files with custom matchers and macros, etc, 17 | # in spec/support/ and its subdirectories. 18 | Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 19 | 20 | RSpec.configure do |config| 21 | # ## Mock Framework 22 | # 23 | # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 24 | # 25 | # config.mock_with :mocha 26 | # config.mock_with :flexmock 27 | # config.mock_with :rr 28 | 29 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 30 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 31 | 32 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 33 | # examples within a transaction, remove the following line or assign false 34 | # instead of true. 35 | config.use_transactional_fixtures = true 36 | 37 | # If true, the base class of anonymous controllers will be inferred 38 | # automatically. This will be the default behavior in future versions of 39 | # rspec-rails. 40 | config.infer_base_class_for_anonymous_controllers = false 41 | config.include Devise::TestHelpers, :type => :controller 42 | config.extend ControllerMacros, :type => :controller 43 | end 44 | end 45 | 46 | Spork.each_run do 47 | # This code will be run each time you run your specs. 48 | 49 | end 50 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do 5 | watch('config/application.rb') 6 | watch('config/environment.rb') 7 | watch(%r{^config/environments/.+\.rb$}) 8 | watch(%r{^config/initializers/.+\.rb$}) 9 | watch('Gemfile') 10 | watch('Gemfile.lock') 11 | watch('spec/spec_helper.rb') { :rspec } 12 | watch('test/test_helper.rb') { :test_unit } 13 | watch(%r{features/support/}) { :cucumber } 14 | end 15 | 16 | guard 'rspec', :version => 2, :cli => '--drb', :all_on_start => false, :all_after_pass => false do 17 | watch(%r{^spec/.+_spec\.rb$}) 18 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } 19 | watch('spec/spec_helper.rb') { "spec" } 20 | 21 | # Rails example 22 | watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 23 | watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } 24 | watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } 25 | watch(%r{^spec/support/(.+)\.rb$}) { "spec" } 26 | watch('config/routes.rb') { "spec/routing" } 27 | watch('app/controllers/application_controller.rb') { "spec/controllers" } 28 | # Capybara request specs 29 | watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } 30 | end 31 | 32 | 33 | guard 'cucumber', :cli => '-c --no-profile --drb --format progress', :all_on_start => false, :all_after_pass => false do 34 | watch(%r{^features/.+\.feature$}) 35 | watch(%r{^features/support/.+$}) { 'features' } 36 | watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' } 37 | end 38 | -------------------------------------------------------------------------------- /db/migrate/20120128225324_devise_create_users.rb: -------------------------------------------------------------------------------- 1 | class DeviseCreateUsers < ActiveRecord::Migration 2 | def change 3 | create_table(:users) do |t| 4 | ## Database authenticatable 5 | t.string :name, :null => false, :default => "" 6 | t.string :email, :null => false, :default => "" 7 | t.string :encrypted_password, :null => false, :default => "" 8 | 9 | ## Recoverable 10 | t.string :reset_password_token 11 | t.datetime :reset_password_sent_at 12 | 13 | ## Rememberable 14 | t.datetime :remember_created_at 15 | 16 | ## Trackable 17 | t.integer :sign_in_count, :default => 0 18 | t.datetime :current_sign_in_at 19 | t.datetime :last_sign_in_at 20 | t.string :current_sign_in_ip 21 | t.string :last_sign_in_ip 22 | 23 | ## Encryptable 24 | t.string :password_salt 25 | 26 | ## Confirmable 27 | # t.string :confirmation_token 28 | # t.datetime :confirmed_at 29 | # t.datetime :confirmation_sent_at 30 | # t.string :unconfirmed_email # Only if using reconfirmable 31 | 32 | ## Lockable 33 | # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts 34 | # t.string :unlock_token # Only if unlock strategy is :email or :both 35 | # t.datetime :locked_at 36 | 37 | ## Token authenticatable 38 | # t.string :authentication_token 39 | 40 | t.integer :up_votes, :null => false, :default => 0 41 | t.integer :down_votes, :null => false, :default => 0 42 | 43 | t.timestamps 44 | end 45 | 46 | add_index :users, :email, :unique => true 47 | add_index :users, :reset_password_token, :unique => true 48 | # add_index :users, :confirmation_token, :unique => true 49 | # add_index :users, :unlock_token, :unique => true 50 | # add_index :users, :authentication_token, :unique => true 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /app/controllers/api/v1/users_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::UsersController < Api::ApplicationController 2 | before_filter :check_login, only: [:update, :notifications] 3 | 4 | # GET /api/v1/user/:id 5 | def show 6 | user = User.find(params[:id]) 7 | 8 | user_json = {:id => user.id, :name => user.name} 9 | # TODO: Email address only for registred users and loged in ? 10 | user_json[:email] = user.email if user_signed_in? 11 | 12 | render :json => user_json 13 | end 14 | 15 | # PUT /api/v1/user 16 | def update 17 | raise Api::BasicApi::NoParameter if params["user"].blank? 18 | 19 | #return render :json => params 20 | #return render :json => {:id => current_user.id, :signed_in => user_signed_in?} 21 | 22 | user = User.find(current_user.id) 23 | if user.update_attributes(params[:user]) 24 | render :json => success_message("Successfully updated user") 25 | else 26 | errors = {:errors => user.errors} 27 | render :json => failure_message("Couldn't update user", errors), 28 | :status => 422 29 | end 30 | end 31 | 32 | # POST /api/v1/signup 33 | def signup 34 | user = User.new(params[:user]) 35 | user.reset_authentication_token! 36 | if user.save 37 | user_json = {:user => { 38 | :name => user.name, 39 | :email => user.email, 40 | :auth_token => user.authentication_token 41 | }} 42 | render :json => success_message("Sign up was successful", user_json), 43 | :status => 201 44 | else 45 | errors = {:errors => user.errors} 46 | render :json => failure_message("Couldn't sign up user", errors), 47 | :status => 422 48 | end 49 | end 50 | 51 | # GET /api/v1/user/notifications 52 | def notifications 53 | notifications = current_user.all_notifications 54 | notifiocations_json = notifications.to_json 55 | 56 | notifications[:new_notifications].update_all(:unread => false) 57 | 58 | render :json => notifiocations_json 59 | end 60 | 61 | end 62 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | if defined?(Bundler) 6 | # If you precompile assets before deploying to production, use this line 7 | Bundler.require(*Rails.groups(:assets => %w(development test))) 8 | # If you want your assets lazily compiled in production, use this line 9 | # Bundler.require(:default, :assets, Rails.env) 10 | end 11 | 12 | module Hackful 13 | class Application < Rails::Application 14 | # Settings in config/environments/* take precedence over those specified here. 15 | # Application configuration should go into files in config/initializers 16 | # -- all .rb files in that directory are automatically loaded. 17 | 18 | # Custom directories with classes and modules you want to be autoloadable. 19 | # config.autoload_paths += %W(#{config.root}/extras) 20 | 21 | # Only load the plugins named here, in the order given (default is alphabetical). 22 | # :all can be used as a placeholder for all plugins not explicitly named. 23 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 24 | 25 | # Activate observers that should always be running. 26 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 27 | 28 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 29 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 30 | # config.time_zone = 'Central Time (US & Canada)' 31 | 32 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 33 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 34 | # config.i18n.default_locale = :de 35 | 36 | # Configure the default encoding used in templates for Ruby 1.9. 37 | config.encoding = "utf-8" 38 | 39 | # Configure sensitive parameters which will be filtered from the log file. 40 | config.filter_parameters += [:password] 41 | 42 | # Enable the asset pipeline 43 | config.assets.enabled = true 44 | 45 | # Version of your assets, change this if you want to expire all your assets 46 | config.assets.version = '1.0' 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /app/controllers/api/v1/sessions_controller.rb: -------------------------------------------------------------------------------- 1 | require "#{File.dirname(__FILE__)}/../basic_api" 2 | class Api::V1::SessionsController < Devise::SessionsController 3 | include Api::BasicApi 4 | 5 | respond_to :json 6 | 7 | prepend_before_filter :require_no_authentication, :only => [:create] 8 | before_filter :set_format 9 | before_filter :check_login, only: :destroy 10 | before_filter :authenticate_user! 11 | 12 | rescue_from Exception do |exception| internal_server_error(exception) end 13 | rescue_from ActionController::UnknownAction, :with => :unknown_action 14 | rescue_from ActionController::RoutingError, :with => :route_not_found 15 | rescue_from ActiveRecord::RecordNotFound, with: :not_found 16 | rescue_from Api::BasicApi::NotLogedIn, with: :not_loged_in 17 | 18 | # POST /api/v1/sessions/login 19 | def create 20 | return invalid_login_attempt if params["user"].nil? 21 | build_resource 22 | email = params["user"]["email"] 23 | password = params["user"]["password"] 24 | resource = User.find_for_database_authentication(:email => email) 25 | return invalid_login_attempt unless resource 26 | return invalid_login_attempt unless resource.valid_password?(password) 27 | 28 | sign_in("user", resource) 29 | resource.ensure_authentication_token! 30 | 31 | user_token_json = { 32 | :auth_token => resource.authentication_token, 33 | :user => { 34 | :id => resource.id, 35 | :name => resource.name, 36 | :email => resource.email, 37 | } 38 | } 39 | return render :json => success_message("Successfully logged in", user_token_json) 40 | end 41 | 42 | # DELETE /api/v1/sessions/logout 43 | def destroy 44 | current_user.authentication_token = nil 45 | current_user.reset_authentication_token! 46 | current_user.save 47 | token = current_user.authentication_token 48 | 49 | signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) 50 | 51 | render :json => success_message("Successfully logged out") 52 | end 53 | 54 | protected 55 | def invalid_login_attempt 56 | warden.custom_failure! 57 | render :json=> failure_message("Email or password incorrect"), :status=>401 58 | end 59 | end -------------------------------------------------------------------------------- /app/controllers/comments_controller.rb: -------------------------------------------------------------------------------- 1 | class CommentsController < FilterController 2 | # GET /comments 3 | # GET /comments.json 4 | def index 5 | redirect_to "/" 6 | end 7 | 8 | # GET /comments/1 9 | # GET /comments/1.json 10 | def show 11 | redirect_to Comment.find(params[:id]).root 12 | end 13 | 14 | # GET /comments/new 15 | # GET /comments/new.json 16 | def new 17 | @comment = Comment.new 18 | 19 | respond_to do |format| 20 | format.html # new.html.erb 21 | format.json { render :json => @comment } 22 | end 23 | end 24 | 25 | # GET /comments/1/edit 26 | def edit 27 | @comment = Comment.find(params[:id]) 28 | end 29 | 30 | # POST /comments 31 | # POST /comments.json 32 | def create 33 | @comment = Comment.new(params[:comment]) 34 | @comment.user_id = current_user.id 35 | 36 | respond_to do |format| 37 | if @comment.save 38 | current_user.up_vote!(@comment) 39 | format.html { redirect_to @comment, :notice => 'Comment was successfully created.' } 40 | format.json { render :json => @comment, :status => :created, :location => @comment } 41 | else 42 | format.html { render :action => "new" } 43 | format.json { render :json => @comment.errors, :status => :unprocessable_entity } 44 | end 45 | end 46 | end 47 | 48 | # PUT /comments/1 49 | # PUT /comments/1.json 50 | def update 51 | @comment = Comment.find(params[:id]) 52 | 53 | respond_to do |format| 54 | if @comment.update_attributes(params[:comment]) 55 | format.html { redirect_to @comment, :notice => 'Comment was successfully updated.' } 56 | format.json { head :ok } 57 | else 58 | format.html { render :action => "edit" } 59 | format.json { render :json => @comment.errors, :status => :unprocessable_entity } 60 | end 61 | end 62 | end 63 | 64 | def vote_up 65 | current_user.up_vote(Comment.find(params[:id])) 66 | end 67 | 68 | def vote_down 69 | current_user.down_vote(Comment.find(params[:id])) 70 | end 71 | 72 | # DELETE /comments/1 73 | # DELETE /comments/1.json 74 | def destroy 75 | @comment = Comment.find(params[:id]) 76 | @comment.destroy 77 | 78 | respond_to do |format| 79 | format.html { redirect_to comments_url } 80 | format.json { head :ok } 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Hackful::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to Rails.root.join("public/assets") 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Use a different logger for distributed setups 37 | # config.logger = SyslogLogger.new 38 | 39 | # Use a different cache store in production 40 | # config.cache_store = :mem_cache_store 41 | 42 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 43 | # config.action_controller.asset_host = "http://assets.example.com" 44 | 45 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 46 | # config.assets.precompile += %w( search.js ) 47 | 48 | # Disable delivery errors, bad email addresses will be ignored 49 | # config.action_mailer.raise_delivery_errors = false 50 | 51 | # Enable threaded mode 52 | # config.threadsafe! 53 | 54 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 55 | # the I18n.default_locale when a translation can not be found) 56 | config.i18n.fallbacks = true 57 | 58 | # Send deprecation notices to registered listeners 59 | config.active_support.deprecation = :notify 60 | end 61 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= @title %><%= " - " if @title.length > 0 %> Hackful Europe 5 | 6 | 7 | 8 | <%= stylesheet_link_tag "application" %> 9 | <%= javascript_include_tag "application" %> 10 | <%= csrf_meta_tags %> 11 | <%= yield :head %> 12 | 13 | 14 |
15 | <%= link_to "Hackful Europe", "/" %> 16 | 17 | <%= link_to "top", "/" %> 18 | <%= link_to "new", "/new" %> 19 | <%= link_to "ask", "/ask" %> 20 | <%= link_to "submit", "/posts/new" %> 21 | <% if user_signed_in? %> 22 | <% if current_user.notifications.where(:unread => true).count > 0 %> 23 | <%= link_to "✉".html_safe, "/notifications", :class => "notification alert" %> 24 | <% else %> 25 | <%= link_to "✉".html_safe, "/notifications", :class => "notification" %> 26 | <% end %> 27 | <% end %> 28 | 29 | 30 | <% if user_signed_in? %> 31 | <%= link_to "✎".html_safe, "/users/edit"%> <%= link_to(current_user.name, user_path(current_user.name)) %>  <%= link_to('Sign out', destroy_user_session_path, :method => :delete) %> 32 | <% else %> 33 | <%= link_to('Sign in', new_user_session_path) %> 34 | <% end %> 35 | 36 |
37 |
<%= notice %>
38 |
39 | <%= yield %> 40 |
41 | 45 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class PostsController < FilterController 2 | # GET /posts 3 | # GET /posts.json 4 | def index 5 | redirect_to "/" 6 | end 7 | 8 | # GET /posts/1 9 | # GET /posts/1.json 10 | def show 11 | @post = Post.find(params[:id]) 12 | @title = @post.title 13 | @parent_comments = @post.comments 14 | @comment = Comment.new 15 | 16 | respond_to do |format| 17 | format.html 18 | format.json { render :json => @post } 19 | end 20 | end 21 | 22 | # GET /posts/new 23 | # GET /posts/new.json 24 | def new 25 | @post = Post.new(:link => params[:link], :title => params[:title]) 26 | 27 | respond_to do |format| 28 | format.html # new.html.erb 29 | format.json { render :json => @post } 30 | end 31 | end 32 | 33 | # GET /posts/1/edit 34 | def edit 35 | @post = Post.find(params[:id]) 36 | end 37 | 38 | # POST /posts 39 | # POST /posts.json 40 | def create 41 | @post = Post.new(params[:post]) 42 | @post.user_id = current_user.id 43 | 44 | respond_to do |format| 45 | if @post.save 46 | current_user.up_vote!(@post) 47 | format.html { redirect_to @post, :notice => 'Post was successfully created.' } 48 | format.json { render :json => @post, :status => :created, :location => @post } 49 | else 50 | format.html { render :action => "new" } 51 | format.json { render :json => @post.errors, :status => :unprocessable_entity } 52 | end 53 | end 54 | end 55 | 56 | # PUT /posts/1 57 | # PUT /posts/1.json 58 | def update 59 | @post = Post.find(params[:id]) 60 | 61 | respond_to do |format| 62 | if @post.update_attributes(params[:post]) 63 | format.html { redirect_to @post, :notice => 'Post was successfully updated.' } 64 | format.json { head :ok } 65 | else 66 | format.html { render :action => "edit" } 67 | format.json { render :json => @post.errors, :status => :unprocessable_entity } 68 | end 69 | end 70 | end 71 | 72 | def vote_up 73 | current_user.up_vote(Post.find(params[:id])) 74 | end 75 | 76 | def vote_down 77 | current_user.down_vote(Post.find(params[:id])) 78 | end 79 | 80 | # DELETE /posts/1 81 | # DELETE /posts/1.json 82 | def destroy 83 | @post = Post.find(params[:id]) 84 | @post.destroy 85 | 86 | respond_to do |format| 87 | format.html { redirect_to posts_url } 88 | format.json { head :ok } 89 | end 90 | end 91 | end 92 | -------------------------------------------------------------------------------- /lib/tasks/cucumber.rake: -------------------------------------------------------------------------------- 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 2 | # It is recommended to regenerate this file in the future when you upgrade to a 3 | # newer version of cucumber-rails. Consider adding your own code to a new file 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 5 | # files. 6 | 7 | 8 | unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks 9 | 10 | vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 11 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? 12 | 13 | begin 14 | require 'cucumber/rake/task' 15 | 16 | namespace :cucumber do 17 | Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| 18 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. 19 | t.fork = true # You may get faster startup if you set this to false 20 | t.profile = 'default' 21 | end 22 | 23 | Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| 24 | t.binary = vendored_cucumber_bin 25 | t.fork = true # You may get faster startup if you set this to false 26 | t.profile = 'wip' 27 | end 28 | 29 | Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| 30 | t.binary = vendored_cucumber_bin 31 | t.fork = true # You may get faster startup if you set this to false 32 | t.profile = 'rerun' 33 | end 34 | 35 | desc 'Run all features' 36 | task :all => [:ok, :wip] 37 | 38 | task :statsetup do 39 | require 'rails/code_statistics' 40 | ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') 41 | ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') 42 | end 43 | end 44 | desc 'Alias for cucumber:ok' 45 | task :cucumber => 'cucumber:ok' 46 | 47 | task :default => :cucumber 48 | 49 | task :features => :cucumber do 50 | STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" 51 | end 52 | 53 | # In case we don't have ActiveRecord, append a no-op task that we can depend upon. 54 | task 'db:test:prepare' do 55 | end 56 | 57 | task :stats => 'cucumber:statsetup' 58 | rescue LoadError 59 | desc 'cucumber rake task not available (cucumber not installed)' 60 | task :cucumber do 61 | abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' 62 | end 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /app/controllers/api/v1/comments_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::CommentsController < Api::ApplicationController 2 | before_filter :check_login, only: [:up_vote, :down_vote, :create, :update, :destroy] 3 | before_filter :set_current_user 4 | 5 | # GET /comment/:id 6 | def show 7 | comment = Comment.find(params[:id]) 8 | raise ActiveRecord::RecordNotFound if comment.nil? 9 | 10 | render :json => comment 11 | end 12 | 13 | # GET /comments/post/:id 14 | def show_post_comments 15 | post = Post.find(params[:id]) 16 | 17 | render :json => all_comments(post) 18 | end 19 | 20 | # GET /comments/user/:id 21 | def show_user_comments 22 | user = User.find(params[:id]) 23 | 24 | render :json => user.comments 25 | end 26 | 27 | # PUT /comment/:id/upvote 28 | def up_vote 29 | comment = Comment.find(params[:id]) 30 | 31 | current_user.up_vote(comment) 32 | 33 | render :json => success_message("Successfully upvoted comment") 34 | end 35 | 36 | # PUT /comment/:id/downvote 37 | def down_vote 38 | comment = Comment.find(params[:id]) 39 | 40 | current_user.down_vote(comment) 41 | 42 | render :json => success_message("Successfully downvoted comment") 43 | end 44 | 45 | # POST /comment 46 | def create 47 | comment = Comment.new(params["comment"]) 48 | comment.user_id = current_user.id 49 | 50 | if comment.save 51 | current_user.up_vote!(comment) 52 | render :json => comment, :status => :created 53 | else 54 | render :json => comment.errors, :status => :unprocessable_entity 55 | end 56 | end 57 | 58 | # PUT /comment/:id 59 | def update 60 | comment = Comment.find(params[:id]) 61 | raise Api::BasicApi::NoPermission unless is_own_comment?(comment) 62 | 63 | if comment.update_attributes(params["comment"]) 64 | head :ok 65 | else 66 | failure = failure_message("Couldn't update comment", {:errors => comment.errors}) 67 | render :json => failure, :status => :unprocessable_entity 68 | end 69 | end 70 | 71 | # DELETE /comment/:id 72 | def destroy 73 | comment = Comment.find(params[:id]) 74 | raise Api::BasicApi::NoPermission unless is_own_comment?(comment) 75 | 76 | comment.destroy 77 | head :ok 78 | end 79 | 80 | private 81 | def is_own_comment?(comment) 82 | return comment.user.eql? current_user 83 | end 84 | 85 | def all_comments(commentable) 86 | children = [] 87 | commentable.comments.each do |comment| 88 | comment_json = comment.as_json 89 | comment_json.merge! ({:children => all_comments(comment)}) 90 | 91 | children.push(comment_json) 92 | end 93 | return children 94 | end 95 | 96 | def set_current_user 97 | User.current_user = current_user if user_signed_in? 98 | end 99 | end -------------------------------------------------------------------------------- /app/controllers/api/v1/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::PostsController < Api::ApplicationController 2 | before_filter :check_login, only: [:up_vote, :down_vote, :create, :update, :destroy] 3 | before_filter :set_current_user 4 | 5 | # GET /post/:id 6 | def show 7 | post = Post.find(params[:id]) 8 | 9 | render :json => post 10 | end 11 | 12 | # GET /posts/user/:id(/:page) 13 | def show_user_posts 14 | user = User.find(params[:id]) 15 | posts = Post.find_user_posts(user, params[:page]) 16 | 17 | render :json => posts 18 | end 19 | 20 | # PUT /post/:id/upvote 21 | def up_vote 22 | post = Post.find(params[:id]) 23 | 24 | current_user.up_vote(post) 25 | 26 | render :json => success_message("Successfully upvoted post") 27 | end 28 | 29 | # PUT /post/:id/unvote 30 | def down_vote 31 | post = Post.find(params[:id]) 32 | 33 | current_user.down_vote(post) 34 | 35 | render :json => success_message("Successfully downvoted post") 36 | end 37 | 38 | # POST /post 39 | def create 40 | post = Post.new(params["post"]) 41 | post.user_id = current_user.id 42 | 43 | if post.save 44 | current_user.up_vote!(post) 45 | status = :created 46 | response = success_message("Successfully created post") 47 | else 48 | status = :unprocessable_entity 49 | errors = {:errors => post.errors} 50 | response = failure_message("Couldn't create post", errors) 51 | end 52 | 53 | render :json => response, :status => status 54 | end 55 | 56 | # PUT /post/:id 57 | def update 58 | post = Post.find(params[:id]) 59 | raise Api::BasicApi::NoPermission unless is_own_post?(post) 60 | 61 | if post.update_attributes(params["post"]) 62 | #head :ok 63 | render :json => {:post => post, :params => params} 64 | else 65 | failure = failure_message("Couldn't update user", {:errors => post.errors}) 66 | render :json => failure, :status => :unprocessable_entity 67 | end 68 | end 69 | 70 | # DELETE /post/:id 71 | def destroy 72 | post = Post.find(params[:id]) 73 | raise Api::BasicApi::NoPermission unless is_own_post?(post) 74 | 75 | post.destroy 76 | head :ok 77 | end 78 | 79 | # GET /posts/frontpage(/:page) 80 | def frontpage 81 | user_signed_in? 82 | return render :json => Post.find_frontpage(params[:page]) 83 | end 84 | 85 | # GET /posts/new(/:page) 86 | def new 87 | return render :json => Post.find_new(params[:page]) 88 | end 89 | 90 | # GET /posts/ask(/:page) 91 | def ask 92 | return render :json => Post.find_ask(params[:page]) 93 | end 94 | 95 | private 96 | def is_own_post?(post) 97 | return post.user.eql? current_user 98 | end 99 | 100 | def set_current_user 101 | User.current_user = current_user if user_signed_in? 102 | end 103 | end 104 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 2 | # It is recommended to regenerate this file in the future when you upgrade to a 3 | # newer version of cucumber-rails. Consider adding your own code to a new file 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 5 | # files. 6 | 7 | require 'rubygems' 8 | require 'spork' 9 | 10 | Spork.prefork do 11 | require 'cucumber/rails' 12 | 13 | 14 | # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In 15 | # order to ease the transition to Capybara we set the default here. If you'd 16 | # prefer to use XPath just remove this line and adjust any selectors in your 17 | # steps to use the XPath syntax. 18 | Capybara.default_selector = :css 19 | 20 | end 21 | 22 | Spork.each_run do 23 | # By default, any exception happening in your Rails application will bubble up 24 | # to Cucumber so that your scenario will fail. This is a different from how 25 | # your application behaves in the production environment, where an error page will 26 | # be rendered instead. 27 | # 28 | # Sometimes we want to override this default behaviour and allow Rails to rescue 29 | # exceptions and display an error page (just like when the app is running in production). 30 | # Typical scenarios where you want to do this is when you test your error pages. 31 | # There are two ways to allow Rails to rescue exceptions: 32 | # 33 | # 1) Tag your scenario (or feature) with @allow-rescue 34 | # 35 | # 2) Set the value below to true. Beware that doing this globally is not 36 | # recommended as it will mask a lot of errors for you! 37 | # 38 | ActionController::Base.allow_rescue = false 39 | 40 | # Remove/comment out the lines below if your app doesn't have a database. 41 | # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. 42 | begin 43 | DatabaseCleaner.strategy = :transaction 44 | rescue NameError 45 | raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." 46 | end 47 | 48 | # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. 49 | # See the DatabaseCleaner documentation for details. Example: 50 | # 51 | # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do 52 | # DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]} 53 | # end 54 | # 55 | # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do 56 | # DatabaseCleaner.strategy = :transaction 57 | # end 58 | # 59 | 60 | # Possible values are :truncation and :transaction 61 | # The :transaction strategy is faster, but might give you threading problems. 62 | # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature 63 | Cucumber::Rails::Database.javascript_strategy = :truncation 64 | 65 | end 66 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | errors: 5 | messages: 6 | expired: "has expired, please request a new one" 7 | not_found: "not found" 8 | already_confirmed: "was already confirmed, please try signing in" 9 | not_locked: "was not locked" 10 | not_saved: 11 | one: "1 error prohibited this %{resource} from being saved:" 12 | other: "%{count} errors prohibited this %{resource} from being saved:" 13 | 14 | devise: 15 | failure: 16 | already_authenticated: 'You are already signed in.' 17 | unauthenticated: 'You need to sign in or sign up before continuing.' 18 | unconfirmed: 'You have to confirm your account before continuing.' 19 | locked: 'Your account is locked.' 20 | invalid: 'Invalid email or password.' 21 | invalid_token: 'Invalid authentication token.' 22 | timeout: 'Your session expired, please sign in again to continue.' 23 | inactive: 'Your account was not activated yet.' 24 | sessions: 25 | signed_in: 'Signed in successfully.' 26 | signed_out: 'Signed out successfully.' 27 | passwords: 28 | send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' 29 | updated: 'Your password was changed successfully. You are now signed in.' 30 | updated_not_active: 'Your password was changed successfully.' 31 | send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail" 32 | confirmations: 33 | send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' 34 | send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.' 35 | confirmed: 'Your account was successfully confirmed. You are now signed in.' 36 | registrations: 37 | signed_up: 'Welcome! You have signed up successfully.' 38 | signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' 39 | signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' 40 | signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' 41 | updated: 'You updated your account successfully.' 42 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." 43 | destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' 44 | unlocks: 45 | send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' 46 | unlocked: 'Your account has been unlocked successfully. Please sign in to continue.' 47 | send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.' 48 | omniauth_callbacks: 49 | success: 'Successfully authorized from %{kind} account.' 50 | failure: 'Could not authorize you from %{kind} because "%{reason}".' 51 | mailer: 52 | confirmation_instructions: 53 | subject: 'Confirmation instructions' 54 | reset_password_instructions: 55 | subject: 'Reset password instructions' 56 | unlock_instructions: 57 | subject: 'Unlock Instructions' 58 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Hackful::Application.routes.draw do 2 | get "admin/mail" 3 | post "admin/send_newsletter" 4 | 5 | get "admin/spam" 6 | post "admin/save_spam_settings" 7 | 8 | match "/about" => "content#about" 9 | 10 | match "/user/:name" => "users#show", :as => 'user' 11 | 12 | #Voting routes 13 | match ":controller/:id/vote_up" => ":controller#vote_up" 14 | match ":controller/:id/vote_down" => ":controller#vote_down" 15 | 16 | match "/frontpage" => "content#frontpage" 17 | match "/notifications" => "content#notifications" 18 | 19 | match "/new" => "content#new" 20 | match "/ask" => "content#ask" 21 | 22 | resources :comments 23 | resources :posts 24 | 25 | devise_for :users 26 | resources :users, has_one: :data_set 27 | 28 | # /api/ 29 | scope 'api' do 30 | # /api/v1 31 | scope 'v1' do 32 | devise_for :users, 33 | :controllers => { :sessions => 'api/v1/sessions' }, 34 | :path_names => { :sign_in => 'login', 35 | :sign_out => 'logout' }, 36 | :path => "sessions", 37 | :only => :sessions 38 | 39 | match 'signup' => 'api/v1/users#signup', via: :post 40 | 41 | match 'user/notifications' => 'api/v1/users#notifications', via: :get 42 | match 'user/:id' => 'api/v1/users#show', via: :get 43 | match 'user' => 'api/v1/users#update', via: :put 44 | 45 | match 'posts/frontpage(/:page)' => 'api/v1/posts#frontpage', via: :get 46 | match 'posts/new(/:page)' => 'api/v1/posts#new', via: :get 47 | match 'posts/ask(/:page)' => 'api/v1/posts#ask', via: :get 48 | 49 | match 'post' => 'api/v1/posts#create', via: :post 50 | match 'post/:id' => 'api/v1/posts#update', via: :put 51 | match 'post/:id' => 'api/v1/posts#destroy', via: :delete 52 | match 'post/:id' => 'api/v1/posts#show', :via => :get 53 | match 'posts/user/:id(/:page)' => 'api/v1/posts#show_user_posts', :via => :get 54 | match 'post/:id/upvote' => 'api/v1/posts#up_vote', via: :put 55 | match 'post/:id/downvote' => 'api/v1/posts#down_vote', via: :put 56 | 57 | match 'comments/user/:id' => 'api/v1/comments#show_user_comments', via: :get 58 | match 'comments/post/:id' => 'api/v1/comments#show_post_comments', via: :get 59 | match 'comment/:id' => 'api/v1/comments#show', via: :get 60 | match 'comment/:id/upvote' => 'api/v1/comments#up_vote', via: :put 61 | match 'comment/:id/downvote' => 'api/v1/comments#down_vote', via: :put 62 | match 'comment' => 'api/v1/comments#create', via: :post 63 | match 'comment/:id' => 'api/v1/comments#update', via: :put 64 | match 'comment/:id' => 'api/v1/comments#destroy', via: :delete 65 | end 66 | 67 | # API call json 404 error 68 | match '*a' => 'api/application#not_found' 69 | root :to => 'api/application#not_found' 70 | end 71 | 72 | devise_for :users 73 | 74 | 75 | # You can have the root of your site routed with "root" 76 | # just remember to delete public/index.html. 77 | root :to => 'content#frontpage' 78 | 79 | # See how all your routes lay out with "rake routes" 80 | 81 | # This is a legacy wild controller route that's not recommended for RESTful applications. 82 | # Note: This route will make all actions in every controller accessible via GET requests. 83 | # match ':controller(/:action(/:id(.:format)))' 84 | end 85 | -------------------------------------------------------------------------------- /app/assets/stylesheets/layout.css.scss: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 0px; 3 | margin: 0px; 4 | font: { 5 | family: helvetica, ubuntu, arial, verdana, sans-serif; 6 | size: 12pt; 7 | } 8 | div { 9 | 10 | } 11 | } 12 | 13 | h1 { 14 | font-size: 12pt; 15 | } 16 | h2 { 17 | font-size: 11pt; 18 | } 19 | 20 | a:link { 21 | text-decoration: none; 22 | } 23 | 24 | a:visited { 25 | text-decoration: none; 26 | } 27 | 28 | .notice { 29 | font-size: 10pt; 30 | padding: { 31 | left: 13%; 32 | right: 10%; 33 | } 34 | line-height: 20px; 35 | color: #797979; 36 | } 37 | 38 | .header { 39 | background: { 40 | color: #EBEBEB; 41 | } 42 | padding: { 43 | left: 10%; 44 | right: 10%; 45 | } 46 | border-bottom: 1px solid #D9D9D9; 47 | height: 40px; 48 | .title { 49 | position: relative; 50 | line-height: 40px; 51 | height: 40px; 52 | margin: { 53 | top: 10px; 54 | left: 5px; 55 | } 56 | font-size: 16pt; 57 | img { 58 | top: 5px; 59 | position: relative; 60 | margin-right: 5px; 61 | } 62 | } 63 | .navigation { 64 | padding: { 65 | left: 3%; 66 | top: 10%; 67 | } 68 | font-size: 12pt; 69 | a { 70 | padding: { 71 | left: 10px; 72 | right: 10px; 73 | top: 5px; 74 | bottom: 5px; 75 | } 76 | margin: { 77 | left: 3px; 78 | right: 3px; 79 | } 80 | border: 1px solid #D9D9D9; 81 | background-color: #E3E3E3; 82 | } 83 | .notification { 84 | } 85 | .alert { 86 | background-color: #E48E69; 87 | } 88 | } 89 | .user { 90 | float: right; 91 | padding: 10px; 92 | font: { 93 | size: 10pt; 94 | weight: bold; 95 | } 96 | } 97 | a { 98 | color: #000; 99 | &:visited { 100 | color: #000; } 101 | &:hover { 102 | color: #000; } 103 | } 104 | margin-bottom: 10px; 105 | } 106 | 107 | .body { 108 | padding: { 109 | left: 13%; 110 | right: 13%; 111 | } 112 | .voted a { 113 | color: #E48E69; 114 | } 115 | .vote a { 116 | color: #3C3C3C; 117 | } 118 | .arrow { 119 | float: left; 120 | width: 20px; 121 | } 122 | .text_body { 123 | margin-left: 20px; 124 | p { 125 | margin-bottom: 6px; 126 | a { 127 | color: #E46934; 128 | } 129 | a:visited { 130 | color: #E4916D; 131 | } 132 | } 133 | } 134 | .comment_form { 135 | margin: { 136 | left: 24px; 137 | top: 4px; 138 | } 139 | } 140 | .infobar { 141 | font: { 142 | size: 8pt; 143 | } 144 | a { 145 | font-weight: bold; 146 | color: #7F7F7F; 147 | } 148 | color: #6A6A6A; 149 | margin: { 150 | left: 4px; 151 | bottom: 3px; 152 | } 153 | } 154 | .host a:link { 155 | font: { 156 | size: 8pt; 157 | } 158 | color: #6A6A6A; 159 | padding-left: 10px; 160 | } 161 | .comment { 162 | margin-bottom: 15px; 163 | font-size: 10pt; 164 | .comment_reply { 165 | border: 1px solid #C8C8C8; 166 | padding: 1px; 167 | margin: { 168 | left: 4px; 169 | top: 2px; 170 | } 171 | background-color: #EBEBEB; 172 | } 173 | } 174 | .comments_box { 175 | margin-left: 20px; 176 | position: relative; 177 | div a { 178 | font-size: 10pt; 179 | } 180 | } 181 | .button { 182 | padding: 2px; 183 | background-color: #EBEBEB; 184 | width: 100px; 185 | text-align: center; 186 | border: 1px solid #C8C8C8; 187 | font-size: 10pt; 188 | } 189 | .post { 190 | padding-bottom: 7px; 191 | margin-bottom: 10px; 192 | .text_body { 193 | font-size: 10pt 194 | } 195 | } 196 | .notification { 197 | border-bottom: 1px solid #D4D4D4; 198 | h2 { 199 | font: { 200 | size: 10pt; 201 | weight: normal; 202 | } 203 | } 204 | } 205 | .new h2 { 206 | font: { 207 | weight: bold; 208 | size: 10pt; 209 | } 210 | } 211 | #comment_text 212 | { 213 | width: 500px; 214 | height: 120px; 215 | } 216 | #post_title, #post_text, #post_link 217 | { 218 | width: 500px; 219 | } 220 | } 221 | 222 | .footer { 223 | border-top: 1px solid #D9D9D9; 224 | background: { 225 | color: #EBEBEB; 226 | } 227 | height: 30px; 228 | text-align: center; 229 | line-height: 30px; 230 | font: { 231 | size: 10pt; 232 | } 233 | margin-top: 10px; 234 | } 235 | 236 | p { 237 | margin: { 238 | top: 2px; 239 | bottom: 2px; 240 | } 241 | padding: 0px; 242 | } 243 | 244 | .page_navigation { 245 | font: { 246 | size: 10pt; 247 | weight: bold; 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | About 2 | === 3 | 4 | Hackful is a platform developed to power http://hackful.com, a place 5 | for European entrepreneurs to share demos, stories or ask questions. 6 | 7 | Developed by [@8bitpal](https://twitter.com/8bitpal) 8 | 9 | Idea by [@rayhanrafiq](https://twitter.com/rayhanrafiq) and [@mattslight](https://twitter.com/mattslight) 10 | 11 | Hosting donated by [incite ict](http://www.incite-ict.com/) 12 | 13 | Setup 14 | === 15 | Hackful runs on mysql. 16 | 17 | Quick fix for getting the configuration to work in OSX as well as in ubuntu 18 | `sudo ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock` 19 | 20 | API 21 | --- 22 | 23 | ### Quick Facts 24 | 25 | * Format for API is JSON 26 | * You can Login with your credential or with a authentication token 27 | * Frontpage, Ask and New resources are avalaible as JSON 28 | * Posts JSON includes voting status, e.g. did you already vote the entry or not 29 | * Submiting, commenting and upvoting can be easily done with API 30 | * You can signup via API 31 | * Notfications are avalaible as JSON if you are logged in 32 | 33 | [Discussion on hackful.com](http://hackful.com/posts/572) 34 | 35 | ### Known issues: 36 | 37 | * Login is not encrypted and this should be fixed 38 | 39 | ### Examples for API: 40 | 41 | ##### Request all posts on frontpage: 42 | ```console 43 | GET http://hackful.com/api/v1/posts/frontpage 44 | ``` 45 | 46 | ##### Response: 47 | 48 | [{ 49 | "created_at":"2012-03-24T10:11:14Z", 50 | "down_votes":0, 51 | "id":49, 52 | "link":"http://www.balkanventureforum.org/", 53 | "text":"Balkan Venture Forum April 2012", 54 | "title":"Balkan Venture Forum April 2012", 55 | "up_votes":4, 56 | "updated_at":"2012-03-26T18:48:19Z", 57 | "comment_count":6, 58 | "path":"/posts/49", 59 | "voted":false, 60 | "user":{ 61 | "id":1, 62 | "name":"Oemera" 63 | } 64 | }, ...] 65 | 66 | ##### Request all comments for a post: 67 | ```console 68 | GET http://hackful.com/api/v1/posts/frontpage 69 | ``` 70 | 71 | ##### Response: 72 | 73 | [{ 74 | "commentable_id":49, 75 | "created_at":"2012-03-24T10:12:21Z", 76 | "id":34, 77 | "text":"asdasdasd", 78 | "up_votes":1, 79 | "updated_at":"2012-03-24T10:12:21Z", 80 | "voted":false, 81 | "user":{ 82 | "id":9, 83 | "name":"AwesomeGuy" 84 | }, 85 | "children":[ 86 | { 87 | "commentable_id":34, 88 | "created_at":"2012-03-24T10:12:26Z", 89 | "id":35, 90 | "text":"asdasdasd", 91 | "up_votes":1, 92 | "updated_at":"2012-03-24T10:12:26Z", 93 | "voted":false, 94 | "user":{ 95 | "id":9, 96 | "name":"AwesomeGuy" 97 | }, 98 | "children":[] 99 | }, ... ] 100 | }, ...] 101 | 102 | ##### Login and recieve a auth_token: 103 | ```console 104 | POST http://hackful.com/api/v1/sessions/login 105 | user[email]=david@example.com&user[password]=mypassword 106 | ``` 107 | 108 | ##### Response: 109 | 110 | { 111 | "success":true, 112 | "message":"Successfully logged in", 113 | "auth_token":"xHpdsVa5QqahMRxqc4zc", 114 | "user":{ 115 | "id":8, 116 | "name":"RandomGuy", 117 | "email":"random@example.com" 118 | } 119 | } 120 | 121 | ##### Upvote a post 122 | ```console 123 | PUT http://hackful.com/api/v1/post/1/upvote 124 | auth_token=1ZwyJfbv7eiiLE7Gipsv 125 | ``` 126 | 127 | ##### Submit a new article: 128 | ```console 129 | POST http://hackful.com/api/v1/post 130 | auth_token=1ZwyJfbv7eiiLE7Gipsv&post[text]=Text&post[title]=Title&post[link]=http://example.com 131 | ``` 132 | 133 | ### All implemented API methods: 134 | 135 | POST /api/v1/signup 136 | 137 | GET /api/v1/user/:id 138 | GET /api/v1/user/notifications 139 | PUT /api/v1/user 140 | 141 | GET /api/v1/posts/frontpage(/:page) 142 | GET /api/v1/posts/new(/:page) 143 | GET /api/v1/posts/ask(/:page) 144 | GET /api/v1/posts/user/:id(/:page) 145 | 146 | GET /api/v1/post/:id 147 | POST /api/v1/post 148 | PUT /api/v1/post/:id 149 | DELETE /api/v1/post/:id 150 | PUT /api/v1/post/:id/upvote 151 | PUT /api/v1/post/:id/downvote 152 | 153 | GET /api/v1/comments/user/:id 154 | GET /api/v1/comments/post/:id 155 | GET /api/v1/comment/:id 156 | POST /api/v1/comment 157 | PUT /api/v1/comment/:id 158 | DELETE /api/v1/comment/:id 159 | PUT /api/v1/comment/:id/upvote 160 | PUT /api/v1/comment/:id/downvote 161 | 162 | Contribution 163 | --- 164 | 165 | Please post feature requests or bugs as issues. 166 | 167 | Testing 168 | --- 169 | 170 | Cucumber test cases are almost done and on the way. 171 | 172 | ToDo's 173 | ---- 174 | 175 | * Write wiki article for hackful API 176 | * Encrypt API login (password is send without encryption to API) 177 | -------------------------------------------------------------------------------- /app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ActiveRecord::Base 2 | include Rails.application.routes.url_helpers 3 | 4 | has_many :comments, :as => :commentable, :order => "((comments.up_votes - comments.down_votes) - 1 )/POW((((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(comments.created_at)) / 3600 )+2), 1.5) DESC" 5 | belongs_to :user 6 | 7 | attr_accessible :commentable_type, :commentable_id, :title, :text, :link 8 | 9 | validates :link, :format => URI::regexp(%w(http https)), :allow_blank => true 10 | validates :title, :length => { :maximum => 255 }, :allow_blank => false 11 | validates :text, :length => { :minimum => 2 }, :allow_blank => false 12 | 13 | make_voteable 14 | 15 | # Finds user posts with given page and standard ordering 16 | # (see Post.order_algorithm for order algorithm). 17 | def self.find_user_posts(user, page = nil) 18 | self.find_ordered self.offset(page), "user_id = #{user.id}" 19 | end 20 | 21 | # Finds frontpage posts with given page and standard ordering 22 | # (see Post.order_algorithm for order algorithm). 23 | def self.find_frontpage(page = nil) 24 | self.find_ordered self.offset(page) 25 | end 26 | 27 | # Finds ask posts with given page and standard ordering 28 | # (see Post.order_algorithm for order algorithm). 29 | def self.find_ask(page = nil) 30 | self.find_ordered self.offset(page), "link = ''" 31 | end 32 | 33 | # Finds new posts with given page and DESC ordering. 34 | def self.find_new(page = nil) 35 | offset = self.offset(page) 36 | Post.find(:all, :order => "created_at DESC", :limit => 20, :offset => offset) 37 | end 38 | 39 | # Overrides standard as_json and a adds user, comment count, path and vote 40 | # status to post json. 41 | # 42 | # ==== Examples 43 | # 44 | # [{ 45 | # "created_at":"2012-03-24T10:11:14Z", 46 | # "down_votes":0, 47 | # "id":1, 48 | # "link":"http://http://example.com/", 49 | # "text":"Example Post Text", 50 | # "title":"Example Post Title", 51 | # "up_votes":4, 52 | # "updated_at":"2012-03-26T18:48:19Z", 53 | # "comment_count":6, 54 | # "path":"/posts/1", 55 | # "voted":false, 56 | # "user":{ 57 | # "id":1, 58 | # "name":"Oemera" 59 | # } 60 | # }, ...] 61 | def as_json(options = {}) 62 | super( 63 | :include => {:user => {:only => [:id, :name]}}, 64 | :except => :user_id, 65 | :methods => [:comment_count, :path, :voted] 66 | ) 67 | end 68 | 69 | # Returns comment count. 70 | def comment_count 71 | Post.count_all_comments(comments) 72 | end 73 | 74 | # Return path for post. 75 | def path 76 | post_path(self) 77 | end 78 | 79 | # Checks if current logged in user has upvoted the post or not. 80 | # If no current user exists, it will return false. 81 | def voted 82 | current_user = User.current_user 83 | unless current_user.blank? 84 | current_user.voted?(self) 85 | else 86 | false 87 | end 88 | end 89 | 90 | private 91 | 92 | # Finds posts with standard algorithm, a offset and a optional where clause. 93 | # If no where clause is given the where whole where clause will be left out. 94 | # However you the where clause should be written in SQL syntax and shouldn't 95 | # contain the WHERE keyword. 96 | # 97 | # ==== Examples 98 | # 99 | # Post.find_ordered(0, "user_id = 1") 100 | # Post.find_ordered(20, "link = ''") 101 | # Post.find_ordered(0, nil) 102 | # 103 | def self.find_ordered(offset, where = nil) 104 | where = where.nil? ? "" : "WHERE #{where}" 105 | sql = "SELECT * FROM posts 106 | #{where} 107 | ORDER BY #{order_algorithm} 108 | DESC LIMIT ?, 20" 109 | 110 | Post.find_by_sql [sql, offset] 111 | end 112 | 113 | # Converts a page number into offset for limiting database queries. 114 | # If page is nil or smaller than 1 page value will be set 115 | # to 1. 116 | def self.offset(page = nil) 117 | if page.nil? or page.blank? or page.to_i < 1 then page = 1 end 118 | offset = ((page.to_i-1)*20) 119 | end 120 | 121 | # Contains the order algorithm for content pages like frontpage, ask and new. 122 | # Whole method is static and has no dynimcs in it but it makes the SQL 123 | # statements a lot easier to read. 124 | def self.order_algorithm 125 | date_diff = "((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(posts.created_at))" 126 | order_algorithm = "((posts.up_votes - posts.down_votes) -1)/ 127 | POW((#{date_diff} / 3600)+2), 1.5)" 128 | end 129 | 130 | # Counts all comments of a post recursively. 131 | # This is needed cause all comments are stored as children of a commentable 132 | # object. So we can't just do post.comments.length. We need to 133 | # iterate through all comments children recursively. 134 | def self.count_all_comments(comments) 135 | count = 0 136 | comments.each do |comment| 137 | count = count + 1 138 | count += count_all_comments(comment.comments) 139 | end 140 | return count 141 | end 142 | end 143 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20120307155241) do 15 | 16 | create_table "admin_auths", :force => true do |t| 17 | t.integer "user_id" 18 | t.string "resource" 19 | t.string "action" 20 | t.datetime "created_at" 21 | t.datetime "updated_at" 22 | end 23 | 24 | create_table "comments", :force => true do |t| 25 | t.integer "user_id" 26 | t.text "text" 27 | t.integer "commentable_id" 28 | t.string "commentable_type" 29 | t.integer "up_votes", :default => 0, :null => false 30 | t.integer "down_votes", :default => 0, :null => false 31 | t.datetime "created_at" 32 | t.datetime "updated_at" 33 | end 34 | 35 | create_table "data_sets", :force => true do |t| 36 | t.integer "user_id" 37 | t.boolean "contact_me", :default => true 38 | t.string "twitter" 39 | t.string "github" 40 | t.string "linkedin" 41 | t.string "url" 42 | t.string "blog" 43 | t.text "about_me" 44 | t.datetime "created_at" 45 | t.datetime "updated_at" 46 | end 47 | 48 | create_table "delayed_jobs", :force => true do |t| 49 | t.integer "priority", :default => 0 50 | t.integer "attempts", :default => 0 51 | t.text "handler" 52 | t.text "last_error" 53 | t.datetime "run_at" 54 | t.datetime "locked_at" 55 | t.datetime "failed_at" 56 | t.string "locked_by" 57 | t.string "queue" 58 | t.datetime "created_at" 59 | t.datetime "updated_at" 60 | end 61 | 62 | add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" 63 | 64 | create_table "notifications", :force => true do |t| 65 | t.integer "user_id" 66 | t.boolean "unread", :default => true 67 | t.integer "alerted_id" 68 | t.string "alerted_type" 69 | t.integer "alertable_id" 70 | t.string "alertable_type" 71 | t.datetime "created_at" 72 | t.datetime "updated_at" 73 | end 74 | 75 | create_table "posts", :force => true do |t| 76 | t.integer "user_id" 77 | t.string "title" 78 | t.text "text" 79 | t.text "link" 80 | t.integer "up_votes", :default => 0, :null => false 81 | t.integer "down_votes", :default => 0, :null => false 82 | t.datetime "created_at" 83 | t.datetime "updated_at" 84 | end 85 | 86 | create_table "users", :force => true do |t| 87 | t.string "name", :default => "", :null => false 88 | t.string "email", :default => "", :null => false 89 | t.string "encrypted_password", :default => "", :null => false 90 | t.string "reset_password_token" 91 | t.datetime "reset_password_sent_at" 92 | t.datetime "remember_created_at" 93 | t.integer "sign_in_count", :default => 0 94 | t.datetime "current_sign_in_at" 95 | t.datetime "last_sign_in_at" 96 | t.string "current_sign_in_ip" 97 | t.string "last_sign_in_ip" 98 | t.string "password_salt" 99 | t.integer "up_votes", :default => 0, :null => false 100 | t.integer "down_votes", :default => 0, :null => false 101 | t.datetime "created_at" 102 | t.datetime "updated_at" 103 | t.string "authentication_token" 104 | end 105 | 106 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true 107 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true 108 | 109 | create_table "votings", :force => true do |t| 110 | t.string "voteable_type" 111 | t.integer "voteable_id" 112 | t.string "voter_type" 113 | t.integer "voter_id" 114 | t.boolean "up_vote", :null => false 115 | t.datetime "created_at" 116 | t.datetime "updated_at" 117 | end 118 | 119 | add_index "votings", ["voteable_type", "voteable_id", "voter_type", "voter_id"], :name => "unique_voters", :unique => true 120 | add_index "votings", ["voteable_type", "voteable_id"], :name => "index_votings_on_voteable_type_and_voteable_id" 121 | add_index "votings", ["voter_type", "voter_id"], :name => "index_votings_on_voter_type_and_voter_id" 122 | 123 | end 124 | -------------------------------------------------------------------------------- /spec/controllers/posts_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe PostsController do 4 | login_user 5 | let(:new_post) { FactoryGirl.create :post, user_id: subject.current_user.id } 6 | 7 | before(:each) do 8 | Post.stub(:find).and_return(new_post) 9 | end 10 | 11 | describe "GET 'index'" do 12 | it "returns http sucess" do 13 | get 'index' 14 | response.should redirect_to root_path 15 | end 16 | end 17 | 18 | describe "GET 'show'" do 19 | it "gets posts for id" do 20 | get 'show', id: "1" 21 | response.should be_success 22 | end 23 | 24 | it "gets posts for id as JSON" do 25 | get 'show', id: "1", format: :json 26 | response.should be_success 27 | end 28 | end 29 | 30 | describe "GET 'new'" do 31 | context "when signed in" do 32 | 33 | it "returns http success" do 34 | get 'new' 35 | response.should be_success 36 | end 37 | 38 | it "gets posts for id as JSON" do 39 | get 'new' 40 | response.should be_success 41 | end 42 | end 43 | context "when not signed in" do 44 | it "redirects to signin when requesting html" do 45 | controller.stub(:current_user).and_return(nil) 46 | get 'new' 47 | response.should redirect_to new_user_session_path 48 | end 49 | 50 | it "redirects to signin when requesting JSON" do 51 | controller.stub(:current_user).and_return(nil) 52 | get 'new' 53 | response.should redirect_to new_user_session_path 54 | end 55 | end 56 | end 57 | 58 | describe "GET 'edit'" do 59 | context "when signed in" do 60 | login_user 61 | 62 | it "creates a new post" do 63 | get 'edit', id: new_post.id 64 | response.should be_success 65 | end 66 | end 67 | context "when not signed in" do 68 | it "redirects to signin when requesting html" do 69 | controller.stub(:current_user).and_return(nil) 70 | get 'edit', id: new_post.id 71 | response.should redirect_to new_user_session_path 72 | end 73 | end 74 | end 75 | 76 | describe "POST 'create'" do 77 | context "when signed in" do 78 | it "sends http success" do 79 | post 'create', post: new_post.attributes 80 | flash[:notice].should match('Post was successfully created.') 81 | response.should redirect_to post_path(assigns[:post]) 82 | end 83 | 84 | context "on successful save" do 85 | it "makes the user upvote the post" do 86 | Post.stub(:new).and_return(new_post) 87 | subject.current_user.should_receive(:up_vote!).with(new_post) 88 | post 'create', post: new_post.attributes 89 | end 90 | 91 | it "renders json for post" do 92 | post 'create', post: new_post.attributes, format: :json 93 | json = JSON.parse(response.body) 94 | json["text"].length.should > 0 95 | response.status.should == 201 96 | end 97 | end 98 | 99 | context "on unsuccessful save" do 100 | it "renders the new template" do 101 | Post.any_instance.stub(:save).and_return(false) 102 | post 'create', post: new_post.attributes 103 | response.should render_template("new") 104 | end 105 | 106 | it "renders json with post.errors" do 107 | post 'create', post: { title: "" }, format: :json 108 | response.body.should match("too short") 109 | response.status.should == 422 110 | end 111 | end 112 | end 113 | 114 | context "when not signed in" do 115 | it "redirects to singin_path" do 116 | controller.stub(:current_user).and_return(nil) 117 | post 'create', post: new_post.attributes 118 | response.should redirect_to new_user_session_path 119 | end 120 | end 121 | end 122 | 123 | describe "PUT 'update'" do 124 | context "when signed in" do 125 | it "sends http success" do 126 | put 'update', id: new_post.id 127 | flash[:notice].should match('Post was successfully updated.') 128 | response.should redirect_to post_path(assigns[:post]) 129 | end 130 | 131 | context "on successful update" do 132 | it "renders json for post" do 133 | put 'update', id: new_post.id, format: :json 134 | response.body.should == " " 135 | response.should be_success 136 | end 137 | end 138 | 139 | context "on unsuccessful save" do 140 | it "renders the edit template" do 141 | Post.any_instance.stub(:save).and_return(false) 142 | put 'update', id: new_post.id 143 | response.should render_template("edit") 144 | end 145 | 146 | it "renders json with post.errors" do 147 | put 'update', id: new_post.id, post: { link: "none" }, format: :json 148 | response.body.should match("is invalid") 149 | response.status.should == 422 150 | end 151 | end 152 | end 153 | 154 | context "when not signed in" do 155 | it "redirects to singin_path" do 156 | controller.stub(:current_user).and_return(nil) 157 | put 'update', id: new_post.id 158 | response.should redirect_to new_user_session_path 159 | end 160 | end 161 | end 162 | 163 | describe "DELETE 'destroy'" do 164 | it "should destroy model and redirect to index action" do 165 | delete :destroy, id: new_post.id 166 | response.should redirect_to(posts_url) 167 | Post.exists?(new_post.id).should be_false 168 | end 169 | 170 | it "should redirect to index action when trying to delete non-existant post" do 171 | delete :destroy, id: "9999" 172 | response.should redirect_to(posts_url) 173 | Post.exists?(new_post.id).should be_false 174 | end 175 | end 176 | 177 | #TODO FIX This is broken. No template to render 178 | #describe "#vote_up" do 179 | # it "sends vote up message to User" do 180 | # get 'vote_up', id: "1", format: :json 181 | # subject.current_user.should_receive(:vote_down).once 182 | # end 183 | #end 184 | # 185 | ##TODO FIX This is broken. No template to render 186 | #describe "#vote_down" do 187 | # it "sends vote down message to User" do 188 | # get 'vote_down', id: "1", format: :json 189 | # subject.current_user.should_receive(:vote_up).once 190 | # end 191 | # it "does not vote up if the user has already voted" 192 | #end 193 | end 194 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: git://github.com/fxposter/nested_form.git 3 | revision: 94dc6456cb07736825bf687c898e953c32e68587 4 | specs: 5 | nested_form (0.2.2) 6 | 7 | GEM 8 | remote: http://rubygems.org/ 9 | remote: http://gemcutter.org/ 10 | specs: 11 | actionmailer (3.1.10) 12 | actionpack (= 3.1.10) 13 | mail (~> 2.3.3) 14 | actionpack (3.1.10) 15 | activemodel (= 3.1.10) 16 | activesupport (= 3.1.10) 17 | builder (~> 3.0.0) 18 | erubis (~> 2.7.0) 19 | i18n (~> 0.6) 20 | rack (~> 1.3.6) 21 | rack-cache (~> 1.2) 22 | rack-mount (~> 0.8.2) 23 | rack-test (~> 0.6.1) 24 | sprockets (~> 2.0.4) 25 | activemodel (3.1.10) 26 | activesupport (= 3.1.10) 27 | builder (~> 3.0.0) 28 | i18n (~> 0.6) 29 | activerecord (3.1.10) 30 | activemodel (= 3.1.10) 31 | activesupport (= 3.1.10) 32 | arel (~> 2.2.3) 33 | tzinfo (~> 0.3.29) 34 | activeresource (3.1.10) 35 | activemodel (= 3.1.10) 36 | activesupport (= 3.1.10) 37 | activesupport (3.1.10) 38 | multi_json (>= 1.0, < 1.3) 39 | addressable (2.3.2) 40 | arel (2.2.3) 41 | bcrypt-ruby (3.0.1) 42 | builder (3.0.4) 43 | cancan (1.6.9) 44 | capybara (2.0.2) 45 | mime-types (>= 1.16) 46 | nokogiri (>= 1.3.3) 47 | rack (>= 1.0.0) 48 | rack-test (>= 0.5.4) 49 | selenium-webdriver (~> 2.0) 50 | xpath (~> 1.0.0) 51 | capybara-webkit (0.14.1) 52 | capybara (~> 2.0, >= 2.0.2) 53 | json 54 | childprocess (0.3.8) 55 | ffi (~> 1.0, >= 1.0.11) 56 | chronic (0.9.0) 57 | coderay (1.0.8) 58 | coffee-rails (3.1.1) 59 | coffee-script (>= 2.2.0) 60 | railties (~> 3.1.0) 61 | coffee-script (2.2.0) 62 | coffee-script-source 63 | execjs 64 | coffee-script-source (1.4.0) 65 | cucumber (1.2.1) 66 | builder (>= 2.1.2) 67 | diff-lcs (>= 1.1.3) 68 | gherkin (~> 2.11.0) 69 | json (>= 1.4.6) 70 | cucumber-rails (1.3.0) 71 | capybara (>= 1.1.2) 72 | cucumber (>= 1.1.8) 73 | nokogiri (>= 1.5.0) 74 | database_cleaner (0.9.1) 75 | delayed_job (3.0.5) 76 | activesupport (~> 3.0) 77 | delayed_job_active_record (0.4.1) 78 | activerecord (>= 2.1.0, < 4) 79 | delayed_job (~> 3.0) 80 | devise (2.2.3) 81 | bcrypt-ruby (~> 3.0) 82 | orm_adapter (~> 0.1) 83 | railties (~> 3.1) 84 | warden (~> 1.2.1) 85 | diff-lcs (1.2.1) 86 | erubis (2.7.0) 87 | execjs (1.4.0) 88 | multi_json (~> 1.0) 89 | factory_girl (4.2.0) 90 | activesupport (>= 3.0.0) 91 | factory_girl_rails (4.2.1) 92 | factory_girl (~> 4.2.0) 93 | railties (>= 3.0.0) 94 | faker (1.1.2) 95 | i18n (~> 0.5) 96 | fakeweb (1.3.0) 97 | ffi (1.3.1) 98 | gherkin (2.11.6) 99 | json (>= 1.7.6) 100 | hike (1.2.1) 101 | i18n (0.6.1) 102 | jquery-rails (2.2.1) 103 | railties (>= 3.0, < 5.0) 104 | thor (>= 0.14, < 2.0) 105 | json (1.7.7) 106 | launchy (2.2.0) 107 | addressable (~> 2.3) 108 | libv8 (3.11.8.13) 109 | mail (2.3.3) 110 | i18n (>= 0.4.0) 111 | mime-types (~> 1.16) 112 | treetop (~> 1.4.8) 113 | make_voteable (0.1.1) 114 | activerecord (~> 3.0) 115 | method_source (0.8.1) 116 | mime-types (1.21) 117 | multi_json (1.2.0) 118 | mysql2 (0.3.11) 119 | nokogiri (1.5.6) 120 | orm_adapter (0.4.0) 121 | polyglot (0.3.3) 122 | pry (0.9.12) 123 | coderay (~> 1.0.5) 124 | method_source (~> 0.8) 125 | slop (~> 3.4) 126 | rack (1.3.10) 127 | rack-cache (1.2) 128 | rack (>= 0.4) 129 | rack-mount (0.8.3) 130 | rack (>= 1.0.0) 131 | rack-ssl (1.3.3) 132 | rack 133 | rack-test (0.6.2) 134 | rack (>= 1.0) 135 | rails (3.1.10) 136 | actionmailer (= 3.1.10) 137 | actionpack (= 3.1.10) 138 | activerecord (= 3.1.10) 139 | activeresource (= 3.1.10) 140 | activesupport (= 3.1.10) 141 | bundler (~> 1.0) 142 | railties (= 3.1.10) 143 | rails_autolink (1.0.9) 144 | rails (~> 3.1) 145 | railties (3.1.10) 146 | actionpack (= 3.1.10) 147 | activesupport (= 3.1.10) 148 | rack-ssl (~> 1.3.2) 149 | rake (>= 0.8.7) 150 | rdoc (~> 3.4) 151 | thor (~> 0.14.6) 152 | rake (10.0.3) 153 | rdiscount (2.0.7) 154 | rdoc (3.12.1) 155 | json (~> 1.4) 156 | ref (1.0.2) 157 | rest-client (1.6.7) 158 | mime-types (>= 1.16) 159 | rspec (2.0.1) 160 | rspec-core (~> 2.0.1) 161 | rspec-expectations (~> 2.0.1) 162 | rspec-mocks (~> 2.0.1) 163 | rspec-core (2.0.1) 164 | rspec-expectations (2.0.1) 165 | diff-lcs (>= 1.1.2) 166 | rspec-mocks (2.0.1) 167 | rspec-core (~> 2.0.1) 168 | rspec-expectations (~> 2.0.1) 169 | rspec-rails (2.0.1) 170 | rspec (~> 2.0.0) 171 | rubyzip (0.9.9) 172 | sass (3.2.5) 173 | sass-rails (3.1.7) 174 | actionpack (~> 3.1.0) 175 | railties (~> 3.1.0) 176 | sass (>= 3.1.10) 177 | tilt (~> 1.3.2) 178 | selenium-webdriver (2.29.0) 179 | childprocess (>= 0.2.5) 180 | multi_json (~> 1.0) 181 | rubyzip 182 | websocket (~> 1.0.4) 183 | slop (3.4.3) 184 | sprockets (2.0.4) 185 | hike (~> 1.2) 186 | rack (~> 1.0) 187 | tilt (~> 1.1, != 1.3.0) 188 | sqlite3 (1.3.7) 189 | therubyracer (0.11.3) 190 | libv8 (~> 3.11.8.12) 191 | ref 192 | thor (0.14.6) 193 | tilt (1.3.3) 194 | treetop (1.4.12) 195 | polyglot 196 | polyglot (>= 0.3.1) 197 | tzinfo (0.3.35) 198 | uglifier (1.3.0) 199 | execjs (>= 0.3.0) 200 | multi_json (~> 1.0, >= 1.0.2) 201 | warden (1.2.1) 202 | rack (>= 1.0) 203 | websocket (1.0.7) 204 | whenever (0.8.2) 205 | activesupport (>= 2.3.4) 206 | chronic (>= 0.6.3) 207 | xpath (1.0.0) 208 | nokogiri (~> 1.3) 209 | 210 | PLATFORMS 211 | ruby 212 | 213 | DEPENDENCIES 214 | cancan 215 | capybara 216 | capybara-webkit 217 | coffee-rails 218 | cucumber-rails 219 | database_cleaner 220 | delayed_job 221 | delayed_job_active_record 222 | devise 223 | execjs 224 | factory_girl_rails 225 | faker 226 | fakeweb 227 | jquery-rails 228 | json (>= 1.7.7) 229 | launchy 230 | make_voteable 231 | mysql2 232 | nested_form! 233 | pry 234 | rails (= 3.1.10) 235 | rails_autolink 236 | rdiscount 237 | rest-client 238 | rspec-rails 239 | sass-rails 240 | sqlite3 241 | therubyracer 242 | uglifier (>= 1.0.3) 243 | whenever 244 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # Use this hook to configure devise mailer, warden hooks and so forth. 2 | # Many of these configuration options can be set straight in your model. 3 | Devise.setup do |config| 4 | # ==> Mailer Configuration 5 | # Configure the e-mail address which will be shown in Devise::Mailer, 6 | # note that it will be overwritten if you use your own mailer class with default "from" parameter. 7 | config.mailer_sender = "mail@hackful.com" 8 | 9 | # Configure the class responsible to send e-mails. 10 | # config.mailer = "Devise::Mailer" 11 | 12 | # Automatically apply schema changes in tableless databases 13 | config.apply_schema = false 14 | 15 | # ==> ORM configuration 16 | # Load and configure the ORM. Supports :active_record (default) and 17 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 18 | # available as additional gems. 19 | require 'devise/orm/active_record' 20 | 21 | # ==> Configuration for any authentication mechanism 22 | # Configure which keys are used when authenticating a user. The default is 23 | # just :email. You can configure it to use [:username, :subdomain], so for 24 | # authenticating a user, both parameters are required. Remember that those 25 | # parameters are used only when authenticating and not when retrieving from 26 | # session. If you need permissions, you should implement that in a before filter. 27 | # You can also supply a hash where the value is a boolean determining whether 28 | # or not authentication should be aborted when the value is not present. 29 | # config.authentication_keys = [ :email ] 30 | 31 | # Configure parameters from the request object used for authentication. Each entry 32 | # given should be a request method and it will automatically be passed to the 33 | # find_for_authentication method and considered in your model lookup. For instance, 34 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 35 | # The same considerations mentioned for authentication_keys also apply to request_keys. 36 | # config.request_keys = [] 37 | 38 | # Configure which authentication keys should be case-insensitive. 39 | # These keys will be downcased upon creating or modifying a user and when used 40 | # to authenticate or find a user. Default is :email. 41 | config.case_insensitive_keys = [ :email ] 42 | 43 | # Configure which authentication keys should have whitespace stripped. 44 | # These keys will have whitespace before and after removed upon creating or 45 | # modifying a user and when used to authenticate or find a user. Default is :email. 46 | config.strip_whitespace_keys = [ :email ] 47 | 48 | # Tell if authentication through request.params is enabled. True by default. 49 | # It can be set to an array that will enable params authentication only for the 50 | # given strategies, for example, `config.params_authenticatable = [:database]` will 51 | # enable it only for database (email + password) authentication. 52 | # config.params_authenticatable = true 53 | 54 | # Tell if authentication through HTTP Basic Auth is enabled. False by default. 55 | # It can be set to an array that will enable http authentication only for the 56 | # given strategies, for example, `config.http_authenticatable = [:token]` will 57 | # enable it only for token authentication. 58 | # config.http_authenticatable = false 59 | 60 | # If http headers should be returned for AJAX requests. True by default. 61 | config.http_authenticatable_on_xhr = false 62 | 63 | # The realm used in Http Basic Authentication. "Application" by default. 64 | # config.http_authentication_realm = "Application" 65 | 66 | # It will change confirmation, password recovery and other workflows 67 | # to behave the same regardless if the e-mail provided was right or wrong. 68 | # Does not affect registerable. 69 | # config.paranoid = true 70 | 71 | # By default Devise will store the user in session. You can skip storage for 72 | # :http_auth and :token_auth by adding those symbols to the array below. 73 | # Notice that if you are skipping storage for all authentication paths, you 74 | # may want to disable generating routes to Devise's sessions controller by 75 | # passing :skip => :sessions to `devise_for` in your config/routes.rb 76 | config.skip_session_storage = [:http_auth] 77 | 78 | # ==> Configuration for :database_authenticatable 79 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If 80 | # using other encryptors, it sets how many times you want the password re-encrypted. 81 | # 82 | # Limiting the stretches to just one in testing will increase the performance of 83 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 84 | # a value less than 10 in other environments. 85 | config.stretches = Rails.env.test? ? 1 : 10 86 | 87 | # Setup a pepper to generate the encrypted password. 88 | # config.pepper = "fdefeb4f48c980b478799f703fe76375290cdefa9144a9845df8a9127002700e4daaaa29900093bc7f388fc90bdb62f9c72fcbdac13e254d73a585f8c79cdee5" 89 | 90 | # ==> Configuration for :confirmable 91 | # A period that the user is allowed to access the website even without 92 | # confirming his account. For instance, if set to 2.days, the user will be 93 | # able to access the website for two days without confirming his account, 94 | # access will be blocked just in the third day. Default is 0.days, meaning 95 | # the user cannot access the website without confirming his account. 96 | # config.allow_unconfirmed_access_for = 2.days 97 | 98 | # If true, requires any email changes to be confirmed (exctly the same way as 99 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 100 | # db field (see migrations). Until confirmed new email is stored in 101 | # unconfirmed email column, and copied to email column on successful confirmation. 102 | config.reconfirmable = true 103 | 104 | # Defines which key will be used when confirming an account 105 | # config.confirmation_keys = [ :email ] 106 | 107 | # ==> Configuration for :rememberable 108 | # The time the user will be remembered without asking for credentials again. 109 | # config.remember_for = 2.weeks 110 | 111 | # If true, extends the user's remember period when remembered via cookie. 112 | # config.extend_remember_period = false 113 | 114 | # If true, uses the password salt as remember token. This should be turned 115 | # to false if you are not using database authenticatable. 116 | config.use_salt_as_remember_token = true 117 | 118 | # Options to be passed to the created cookie. For instance, you can set 119 | # :secure => true in order to force SSL only cookies. 120 | # config.cookie_options = {} 121 | 122 | # ==> Configuration for :validatable 123 | # Range for password length. Default is 6..128. 124 | # config.password_length = 6..128 125 | 126 | # Email regex used to validate email formats. It simply asserts that 127 | # an one (and only one) @ exists in the given string. This is mainly 128 | # to give user feedback and not to assert the e-mail validity. 129 | # config.email_regexp = /\A[^@]+@[^@]+\z/ 130 | 131 | # ==> Configuration for :timeoutable 132 | # The time you want to timeout the user session without activity. After this 133 | # time the user will be asked for credentials again. Default is 30 minutes. 134 | # config.timeout_in = 30.minutes 135 | 136 | # ==> Configuration for :lockable 137 | # Defines which strategy will be used to lock an account. 138 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 139 | # :none = No lock strategy. You should handle locking by yourself. 140 | # config.lock_strategy = :failed_attempts 141 | 142 | # Defines which key will be used when locking and unlocking an account 143 | # config.unlock_keys = [ :email ] 144 | 145 | # Defines which strategy will be used to unlock an account. 146 | # :email = Sends an unlock link to the user email 147 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 148 | # :both = Enables both strategies 149 | # :none = No unlock strategy. You should handle unlocking by yourself. 150 | # config.unlock_strategy = :both 151 | 152 | # Number of authentication tries before locking an account if lock_strategy 153 | # is failed attempts. 154 | # config.maximum_attempts = 20 155 | 156 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 157 | # config.unlock_in = 1.hour 158 | 159 | # ==> Configuration for :recoverable 160 | # 161 | # Defines which key will be used when recovering the password for an account 162 | # config.reset_password_keys = [ :email ] 163 | 164 | # Time interval you can reset your password with a reset password key. 165 | # Don't put a too small interval or your users won't have the time to 166 | # change their passwords. 167 | config.reset_password_within = 6.hours 168 | 169 | # ==> Configuration for :encryptable 170 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use 171 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, 172 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) 173 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy 174 | # REST_AUTH_SITE_KEY to pepper) 175 | # config.encryptor = :sha512 176 | 177 | # ==> Configuration for :token_authenticatable 178 | # Defines name of the authentication token params key 179 | config.token_authentication_key = :auth_token 180 | 181 | # ==> Scopes configuration 182 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 183 | # "users/sessions/new". It's turned off by default because it's slower if you 184 | # are using only default views. 185 | config.scoped_views = true 186 | 187 | # Configure the default scope given to Warden. By default it's the first 188 | # devise role declared in your routes (usually :user). 189 | # config.default_scope = :user 190 | 191 | # Configure sign_out behavior. 192 | # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). 193 | # The default is true, which means any logout action will sign out all active scopes. 194 | # config.sign_out_all_scopes = true 195 | 196 | # ==> Navigation configuration 197 | # Lists the formats that should be treated as navigational. Formats like 198 | # :html, should redirect to the sign in page when the user does not have 199 | # access, but formats like :xml or :json, should return 401. 200 | # 201 | # If you have any extra navigational formats, like :iphone or :mobile, you 202 | # should add them to the navigational formats lists. 203 | # 204 | # The "*/*" below is required to match Internet Explorer requests. 205 | config.navigational_formats = ["*/*", :html, :json] 206 | 207 | # The default HTTP method used to sign out a resource. Default is :delete. 208 | config.sign_out_via = :delete 209 | 210 | # ==> OmniAuth 211 | # Add a new OmniAuth provider. Check the wiki for more information on setting 212 | # up on your models and hooks. 213 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' 214 | 215 | # ==> Warden configuration 216 | # If you want to use other strategies, that are not supported by Devise, or 217 | # change the failure app, you can configure them inside the config.warden block. 218 | # 219 | # config.warden do |manager| 220 | # manager.intercept_401 = false 221 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy 222 | # end 223 | end 224 | --------------------------------------------------------------------------------