├── log └── .keep ├── tmp └── .keep ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── public ├── favicon.ico ├── apple-touch-icon.png ├── apple-touch-icon-precomposed.png ├── robots.txt ├── 500.html ├── 422.html └── 404.html ├── test ├── helpers │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── poll_test.rb │ ├── reply_test.rb │ ├── answer_test.rb │ ├── question_test.rb │ └── possible_answer_test.rb ├── controllers │ ├── .keep │ ├── polls_controller_test.rb │ └── questions_controller_test.rb ├── fixtures │ ├── .keep │ ├── files │ │ └── .keep │ ├── replies.yml │ ├── polls.yml │ ├── possible_answers.yml │ ├── questions.yml │ └── answers.yml ├── integration │ └── .keep ├── test_helper.rb ├── factories.rb └── unit │ └── poll_serializer │ └── count_per_month_test.rb ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── channels │ │ │ └── .keep │ │ ├── polls.coffee │ │ ├── questions.coffee │ │ ├── cable.js │ │ ├── application.js │ │ └── graph.js │ ├── config │ │ └── manifest.js │ └── stylesheets │ │ ├── polls.sass │ │ ├── questions.sass │ │ └── application.css.scss ├── models │ ├── concerns │ │ └── .keep │ ├── application_record.rb │ ├── possible_answer.rb │ ├── reply.rb │ ├── answer.rb │ ├── poll.rb │ └── question.rb ├── controllers │ ├── concerns │ │ └── .keep │ ├── application_controller.rb │ ├── replies_controller.rb │ ├── polls_controller.rb │ └── questions_controller.rb ├── views │ ├── layouts │ │ ├── mailer.text.erb │ │ ├── mailer.html.erb │ │ └── application.html.haml │ ├── polls │ │ ├── show.json.jbuilder │ │ ├── index.json.jbuilder │ │ ├── new.html.haml │ │ ├── _poll.json.jbuilder │ │ ├── edit.html.haml │ │ ├── _form.html.haml │ │ ├── _stats.html.haml │ │ ├── index.html.haml │ │ └── show.html.haml │ ├── questions │ │ ├── show.json.jbuilder │ │ ├── index.json.jbuilder │ │ ├── new.html.haml │ │ ├── edit.html.haml │ │ ├── _question.json.jbuilder │ │ ├── show.html.haml │ │ ├── index.html.haml │ │ └── _form.html.haml │ ├── replies │ │ ├── _open.html.haml │ │ ├── new.html.haml │ │ └── _choice.html.haml │ └── application │ │ └── _nav.html.haml ├── helpers │ ├── polls_helper.rb │ ├── questions_helper.rb │ └── application_helper.rb ├── jobs │ └── application_job.rb ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── mailers │ └── application_mailer.rb └── lib │ └── poll_serializer.rb ├── vendor └── assets │ ├── javascripts │ └── .keep │ └── stylesheets │ └── .keep ├── bin ├── bundle ├── rake ├── rails ├── spring ├── update └── setup ├── config ├── spring.rb ├── boot.rb ├── environment.rb ├── cable.yml ├── initializers │ ├── session_store.rb │ ├── mime_types.rb │ ├── application_controller_renderer.rb │ ├── filter_parameter_logging.rb │ ├── cookies_serializer.rb │ ├── backtrace_silencers.rb │ ├── assets.rb │ ├── wrap_parameters.rb │ ├── inflections.rb │ └── new_framework_defaults.rb ├── routes.rb ├── database.yml ├── application.rb ├── locales │ └── en.yml ├── secrets.yml ├── environments │ ├── test.rb │ ├── development.rb │ └── production.rb └── puma.rb ├── config.ru ├── db ├── migrate │ ├── 20170414173133_create_polls.rb │ ├── 20170415201659_create_replies.rb │ ├── 20170414183706_create_questions.rb │ ├── 20170414223744_create_possible_answers.rb │ └── 20170415201917_create_answers.rb ├── seeds.rb └── schema.rb ├── Rakefile ├── README.md ├── .gitignore ├── Gemfile └── Gemfile.lock /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/helpers/polls_helper.rb: -------------------------------------------------------------------------------- 1 | module PollsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/questions_helper.rb: -------------------------------------------------------------------------------- 1 | module QuestionsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/views/polls/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.partial! "polls/poll", poll: @poll 2 | -------------------------------------------------------------------------------- /app/views/polls/index.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.array! @polls, partial: 'polls/poll', as: :poll 2 | -------------------------------------------------------------------------------- /app/views/questions/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.partial! "questions/question", question: @question 2 | -------------------------------------------------------------------------------- /app/views/polls/new.html.haml: -------------------------------------------------------------------------------- 1 | %h1 New poll 2 | 3 | = render 'form' 4 | 5 | = link_to 'Back', polls_path 6 | -------------------------------------------------------------------------------- /app/views/questions/index.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.array! @questions, partial: 'questions/question', as: :question 2 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/possible_answer.rb: -------------------------------------------------------------------------------- 1 | class PossibleAnswer < ApplicationRecord 2 | belongs_to :question, required: false 3 | end 4 | -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/views/questions/new.html.haml: -------------------------------------------------------------------------------- 1 | %h1 New question 2 | 3 | = render 'form' 4 | 5 | = link_to 'Back', @poll, class: "btn btn-default" 6 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /app/views/polls/_poll.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.extract! poll, :id, :title, :created_at, :updated_at 2 | json.url poll_url(poll, format: :json) 3 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery with: :exception 3 | end 4 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | %w( 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ).each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /app/views/questions/edit.html.haml: -------------------------------------------------------------------------------- 1 | %h1 Editing question 2 | 3 | = render 'form' 4 | 5 | = link_to 'Show', @question 6 | \| 7 | = link_to 'Back', questions_path 8 | -------------------------------------------------------------------------------- /app/views/replies/_open.html.haml: -------------------------------------------------------------------------------- 1 | %p 2 | =c.label :value, c.object.question.title 3 | =c.text_field :value, class: "form-control" 4 | =c.hidden_field :question_id -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/models/poll_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PollTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/reply_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ReplyTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/views/questions/_question.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.extract! question, :id, :title, :kind, :poll_id, :created_at, :updated_at 2 | json.url question_url(question, format: :json) 3 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: redis://localhost:6379/1 10 | -------------------------------------------------------------------------------- /test/fixtures/replies.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | poll: one 5 | 6 | two: 7 | poll: two 8 | -------------------------------------------------------------------------------- /test/models/answer_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class AnswerTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/question_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class QuestionTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/models/reply.rb: -------------------------------------------------------------------------------- 1 | class Reply < ApplicationRecord 2 | belongs_to :poll, required:false 3 | has_many :answers 4 | 5 | accepts_nested_attributes_for :answers 6 | end 7 | -------------------------------------------------------------------------------- /test/fixtures/polls.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | title: MyString 5 | 6 | two: 7 | title: MyString 8 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_aniketpoll_session' 4 | -------------------------------------------------------------------------------- /test/models/possible_answer_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PossibleAnswerTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/models/answer.rb: -------------------------------------------------------------------------------- 1 | class Answer < ApplicationRecord 2 | belongs_to :reply ,required: false 3 | belongs_to :question ,required: false 4 | belongs_to :possible_answer ,required: false 5 | end 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 | -------------------------------------------------------------------------------- /app/assets/stylesheets/polls.sass: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the polls controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/questions.sass: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the questions controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/views/polls/edit.html.haml: -------------------------------------------------------------------------------- 1 | %h1 Editing Poll Title 2 | 3 | = render 'form' 4 | 5 | %p.btn-group 6 | = link_to 'Show', @poll, class: "btn btn-default" 7 | = link_to 'Back', polls_path, class: "btn btn-default" 8 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /db/migrate/20170414173133_create_polls.rb: -------------------------------------------------------------------------------- 1 | class CreatePolls < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :polls do |t| 4 | t.string :title 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.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 | -------------------------------------------------------------------------------- /app/views/replies/new.html.haml: -------------------------------------------------------------------------------- 1 | %h1=@poll.title 2 | 3 | =form_for [ @poll, @reply] do |f| 4 | =f.fields_for :answers do |c| 5 | =render c.object.question.kind, c: c 6 | 7 | %p 8 | =f.submit "Finish Poll", class: 'btn btn-primary' -------------------------------------------------------------------------------- /test/fixtures/possible_answers.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | question: one 5 | title: MyString 6 | 7 | two: 8 | question: two 9 | title: MyString 10 | -------------------------------------------------------------------------------- /app/assets/javascripts/polls.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://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/javascripts/questions.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://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /db/migrate/20170415201659_create_replies.rb: -------------------------------------------------------------------------------- 1 | class CreateReplies < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :replies do |t| 4 | t.references :poll, foreign_key: true 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/fixtures/questions.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | title: MyString 5 | kind: MyString 6 | poll: one 7 | 8 | two: 9 | title: MyString 10 | kind: MyString 11 | poll: two 12 | -------------------------------------------------------------------------------- /app/models/poll.rb: -------------------------------------------------------------------------------- 1 | class Poll < ApplicationRecord 2 | validates_presence_of :title 3 | has_many :questions 4 | has_many :replies 5 | 6 | def serialize_for_graph 7 | PollSerializer.count_per_month(self).to_json 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /app/models/question.rb: -------------------------------------------------------------------------------- 1 | class Question < ApplicationRecord 2 | belongs_to :poll ,required:false 3 | 4 | has_many :possible_answers 5 | has_many :answers 6 | 7 | accepts_nested_attributes_for :possible_answers, reject_if: proc { |attributes| attributes['title'].blank? } 8 | end 9 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /app/views/questions/show.html.haml: -------------------------------------------------------------------------------- 1 | %p#notice= notice 2 | 3 | %p 4 | %b Title: 5 | = @question.title 6 | %p 7 | %b Kind: 8 | = @question.kind 9 | %p 10 | %b Poll: 11 | = @question.poll 12 | 13 | = link_to 'Edit', edit_question_path(@question) 14 | \| 15 | = link_to 'Back', questions_path 16 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../config/application', __dir__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | 3 | resources :polls do 4 | resources :questions 5 | resources :replies, only: [ :new, :create ] 6 | end 7 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 8 | root 'polls#index' 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20170414183706_create_questions.rb: -------------------------------------------------------------------------------- 1 | class CreateQuestions < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :questions do |t| 4 | t.string :title 5 | t.string :kind 6 | t.references :poll, foreign_key: true 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20170414223744_create_possible_answers.rb: -------------------------------------------------------------------------------- 1 | class CreatePossibleAnswers < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :possible_answers do |t| 4 | t.references :question, foreign_key: true 5 | t.string :title 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/fixtures/answers.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | reply: one 5 | question: one 6 | possible_answer: one 7 | value: MyString 8 | 9 | two: 10 | reply: two 11 | question: two 12 | possible_answer: two 13 | value: MyString 14 | -------------------------------------------------------------------------------- /app/views/replies/_choice.html.haml: -------------------------------------------------------------------------------- 1 | %p 2 | =c.label :value, c.object.question.title 3 | .radio 4 | -c.object.question.possible_answers.each do |possible_answer| 5 | %p 6 | %label 7 | =c.radio_button :possible_answer_id, possible_answer.id 8 | =possible_answer.title 9 | =c.hidden_field :question_id -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20170415201917_create_answers.rb: -------------------------------------------------------------------------------- 1 | class CreateAnswers < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :answers do |t| 4 | t.references :reply, foreign_key: true 5 | t.references :question, foreign_key: true 6 | t.references :possible_answer, foreign_key: true 7 | t.string :value 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /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 rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | -------------------------------------------------------------------------------- /app/assets/javascripts/cable.js: -------------------------------------------------------------------------------- 1 | // Action Cable provides the framework to deal with WebSockets in Rails. 2 | // You can generate new channels where WebSocket features live using the rails generate channel command. 3 | // 4 | //= require action_cable 5 | //= require_self 6 | //= require_tree ./channels 7 | 8 | (function() { 9 | this.App || (this.App = {}); 10 | 11 | App.cable = ActionCable.createConsumer(); 12 | 13 | }).call(this); 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/views/polls/_form.html.haml: -------------------------------------------------------------------------------- 1 | = form_for @poll do |f| 2 | - if @poll.errors.any? 3 | #error_explanation 4 | %h2= "#{pluralize(@poll.errors.count, "error")} prohibited this poll from being saved:" 5 | %ul 6 | - @poll.errors.full_messages.each do |msg| 7 | %li= msg 8 | 9 | .field 10 | = f.label :title 11 | = f.text_field :title, class: 'form-control' 12 | %p 13 | .actions 14 | = f.submit 'Save', class: "btn btn-primary" 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | -------------------------------------------------------------------------------- /app/views/polls/_stats.html.haml: -------------------------------------------------------------------------------- 1 | #polls_per_month 2 | :javascript 3 | (function($) { 4 | $(function() { 5 | var selector = "#polls_per_month"; 6 | var data = #{@poll.serialize_for_graph}; 7 | 8 | Graph.column(selector,data); 9 | }); 10 | })(jQuery); 11 | 12 | 13 | -content_for :footer do 14 | :javascript 15 | google.setOnLoadCallback(function() { 16 | Graph.instances.forEach(function(instance) { 17 | instance.render(); 18 | }); 19 | }); -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /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 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /app/lib/poll_serializer.rb: -------------------------------------------------------------------------------- 1 | class PollSerializer 2 | def self.count_per_month poll 3 | polls_per_month = poll.replies.group_by { |reply| 4 | reply.created_at.beginning_of_month } 5 | 6 | data = polls_per_month.map { |k,v| v.size } 7 | 8 | { 9 | data: data, 10 | title: "Polls answered by month", 11 | x_axis: { 12 | legend: "Polls per month", 13 | series: polls_per_month.keys.map { |date| date.strftime("%b %Y") } 14 | }, 15 | y_axis: { 16 | legend: "No. polls", 17 | scale: [0, data.max + 1] 18 | } 19 | } 20 | end 21 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore Byebug command history file. 21 | .byebug_history 22 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Aniketpoll 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | config.sass.preferred_syntax= :sass 16 | config.autoload_paths += %W(#{config.root}/app/lib) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ 5 | %title Aniketpoll 6 | = javascript_include_tag "https://www.gstatic.com/charts/loader.js" 7 | = javascript_include_tag 'https://google.com/jsapi' 8 | = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' 9 | = javascript_include_tag 'application', 'data-turbolinks-track': 'reload' 10 | = javascript_include_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" 11 | = csrf_meta_tags 12 | %body 13 | =render 'nav' 14 | .container 15 | =yield 16 | =yield :footer 17 | -------------------------------------------------------------------------------- /app/views/questions/index.html.haml: -------------------------------------------------------------------------------- 1 | %h1 Listing All Questions 2 | 3 | %table 4 | %thead 5 | %tr 6 | %th Title 7 | %th Kind 8 | %th Poll 9 | %th 10 | %th Options 11 | %th 12 | 13 | %tbody 14 | - @questions.each do |question| 15 | %tr 16 | %td= question.title 17 | %td= question.kind 18 | %td= question.poll_id 19 | %td= link_to 'Show', [@poll, question], class: "btn btn-default" 20 | %td= link_to 'Edit', edit_poll_question_path(@poll, question), class: "btn btn-default" 21 | %td= link_to 'Delete', [@poll, question], :method => :delete, :data => { :confirm => 'Are you sure?' }, class: "btn btn-default" 22 | 23 | -------------------------------------------------------------------------------- /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. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /app/views/polls/index.html.haml: -------------------------------------------------------------------------------- 1 | %h1 Listing polls 2 | 3 | %%ul 4 | -@polls.each do |poll| 5 | %p 6 | %li 7 | = link_to poll.title, poll 8 | = link_to 'Edit Name', edit_poll_path(poll), class: "btn btn-default" 9 | | 10 | = link_to 'Add a question', new_poll_question_path(poll), class: "btn btn-default" 11 | | 12 | = link_to 'Answer', new_poll_reply_path(poll), class: "btn btn-default" 13 | | 14 | = link_to 'Back', polls_path(poll), class: "btn btn-default" 15 | | 16 | = link_to 'Delete', poll, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: "btn btn-default" 17 | 18 | %p= link_to 'New Poll', new_poll_path, class: "btn btn-primary" -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /app/controllers/replies_controller.rb: -------------------------------------------------------------------------------- 1 | class RepliesController < ApplicationController 2 | 3 | def new 4 | @poll = Poll.find params[:poll_id] 5 | @reply = @poll.replies.build 6 | 7 | @poll.questions.each { |question| @reply.answers.build question: question} 8 | end 9 | 10 | def create 11 | @poll = Poll.find params[:poll_id] 12 | @reply = @poll.replies.build reply_params 13 | 14 | if @reply.save 15 | redirect_to @poll, notice: "Thank you for taking the poll." 16 | else 17 | render :new 18 | end 19 | end 20 | 21 | private 22 | 23 | def reply_params 24 | params.require(:reply).permit(:poll_id, { answers_attributes: [ :value, :question_id, :reply_id, :possible_answer_id ] }) 25 | end 26 | 27 | end -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css.scss: -------------------------------------------------------------------------------- 1 | @import "bootstrap"; 2 | /* 3 | * This is a manifest file that'll be compiled into application.css, which will include all the files 4 | * listed below. 5 | * 6 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 7 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 8 | * 9 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 10 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 11 | * files in this directory. Styles in this file should be added after the last require_* statement. 12 | * It is generally better to create a new file per style scope. 13 | * 14 | *= require bootstrap 15 | *= require_tree . 16 | *= require_self 17 | */ 18 | 19 | -------------------------------------------------------------------------------- /app/views/questions/_form.html.haml: -------------------------------------------------------------------------------- 1 | = form_for [@poll, @question] do |f| 2 | - if @question.errors.any? 3 | #error_explanation 4 | %h2= "#{pluralize(@question.errors.count, "error")} prohibited this question from being saved:" 5 | %ul 6 | - @question.errors.full_messages.each do |msg| 7 | %li= msg 8 | 9 | %p 10 | = f.label :title 11 | = f.text_field :title, class: "form-control" 12 | 13 | .field 14 | = f.label :kind 15 | .radio 16 | -@kind_options.each do |option| 17 | %label 18 | = f.radio_button :kind, option[1] 19 | = option[0] 20 | 21 | %p 22 | %label Specify some choices: 23 | 24 | =f.fields_for :possible_answers do |c| 25 | %p 26 | =c.text_field :title, placeholder: "Type your choice", class: "form-control" 27 | 28 | .actions 29 | = f.submit 'Save', class: "btn btn-primary" -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rails db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rails log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rails restart' 29 | end 30 | -------------------------------------------------------------------------------- /app/views/application/_nav.html.haml: -------------------------------------------------------------------------------- 1 | %nav.navbar.navbar-default 2 | .container-fluid 3 | / Brand and toggle get grouped for better mobile display 4 | .navbar-header 5 | %button.navbar-toggle.collapsed{"aria-expanded" => "false", "data-target" => "#bs-example-navbar-collapse-1", "data-toggle" => "collapse", :type => "button"} 6 | %span.sr-only Toggle navigation 7 | %span.icon-bar 8 | %span.icon-bar 9 | %span.icon-bar 10 | =link_to "Polling Application", root_path, class: 'navbar-brand' 11 | / Collect the nav links, forms, and other content for toggling 12 | #bs-example-navbar-collapse-1.collapse.navbar-collapse 13 | %ul.nav.navbar-nav 14 | =link_to 'Polls', polls_path, class: 'navbar-brand' 15 | =link_to 'All Questions', '/polls/1/questions', class: 'navbar-brand' 16 | 17 | / /.navbar-collapse 18 | / /.container-fluid 19 | -------------------------------------------------------------------------------- /config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rails secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: bb4bbb5c2e7c37c5299ed9cec3524f7fc0d6759b8162fbeb6659c3ce53d10adb0d6a006afb8dc2e69f5825c81f388eec1d5f0e4f5983cf509efff501fd9f0cc3 15 | 16 | test: 17 | secret_key_base: e19131d25732e3fdc7c8af25af2c0c255765e7ed1205b2454a59d2fe2b5076b2807d06bacd3169d01147f5fa8fea33ead32d64ad843edf96de434ede7c19bbd0 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a starting point to setup your application. 15 | # Add necessary setup steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | # puts "\n== Copying sample files ==" 22 | # unless File.exist?('config/database.yml') 23 | # cp 'config/database.yml.sample', 'config/database.yml' 24 | # end 25 | 26 | puts "\n== Preparing database ==" 27 | system! 'bin/rails db:setup' 28 | 29 | puts "\n== Removing old logs and tempfiles ==" 30 | system! 'bin/rails log:clear tmp:clear' 31 | 32 | puts "\n== Restarting application server ==" 33 | system! 'bin/rails restart' 34 | end 35 | -------------------------------------------------------------------------------- /test/controllers/polls_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PollsControllerTest < ActionDispatch::IntegrationTest 4 | setup do 5 | @poll = polls(:one) 6 | end 7 | 8 | test "should get index" do 9 | get polls_url 10 | assert_response :success 11 | end 12 | 13 | test "should get new" do 14 | get new_poll_url 15 | assert_response :success 16 | end 17 | 18 | test "should create poll" do 19 | assert_difference('Poll.count') do 20 | post polls_url, params: { poll: { title: @poll.title } } 21 | end 22 | 23 | assert_redirected_to poll_url(Poll.last) 24 | end 25 | 26 | test "should show poll" do 27 | get poll_url(@poll) 28 | assert_response :success 29 | end 30 | 31 | test "should get edit" do 32 | get edit_poll_url(@poll) 33 | assert_response :success 34 | end 35 | 36 | test "should update poll" do 37 | patch poll_url(@poll), params: { poll: { title: @poll.title } } 38 | assert_redirected_to poll_url(@poll) 39 | end 40 | 41 | test "should destroy poll" do 42 | assert_difference('Poll.count', -1) do 43 | delete poll_url(@poll) 44 | end 45 | 46 | assert_redirected_to polls_url 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /test/factories.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :answer do 3 | end 4 | 5 | factory :reply do 6 | end 7 | 8 | factory :possible_answer do 9 | title "Possible Answer" 10 | end 11 | 12 | factory :question do 13 | title "Question #" 14 | kind "choice" 15 | 16 | factory :full_question do 17 | ignore do 18 | answers_count 5 19 | possible_answers_count 5 20 | end 21 | 22 | after(:create) do |question, evaluator| 23 | create_list :answer, 24 | evaluator.answers_count, 25 | question: question, 26 | possible_answer_id: 1 27 | 28 | create_list :possible_answer, 29 | evaluator.possible_answers_count, 30 | question: question 31 | end 32 | end 33 | end 34 | 35 | factory :poll do 36 | title "Testing poll" 37 | 38 | factory :full_poll do 39 | 40 | ignore do 41 | replies_count 5 42 | questions_count 5 43 | end 44 | 45 | after(:create) do |poll, evaluator| 46 | create_list :full_question, evaluator.questions_count, poll: poll 47 | create_list :reply, evaluator.replies_count, poll: poll 48 | end 49 | end 50 | end 51 | end -------------------------------------------------------------------------------- /config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Read the Guide for Upgrading Ruby on Rails for more info on each option. 6 | 7 | # Enable per-form CSRF tokens. Previous versions had false. 8 | Rails.application.config.action_controller.per_form_csrf_tokens = true 9 | 10 | # Enable origin-checking CSRF mitigation. Previous versions had false. 11 | Rails.application.config.action_controller.forgery_protection_origin_check = true 12 | 13 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 14 | # Previous versions had false. 15 | ActiveSupport.to_time_preserves_timezone = true 16 | 17 | # Require `belongs_to` associations by default. Previous versions had false. 18 | Rails.application.config.active_record.belongs_to_required_by_default = true 19 | 20 | # Do not halt callback chains when a callback returns false. Previous versions had true. 21 | ActiveSupport.halt_callback_chains_on_return_false = false 22 | 23 | # Configure SSL options to enable HSTS with subdomains. Previous versions had false. 24 | Rails.application.config.ssl_options = { hsts: { subdomains: true } } 25 | -------------------------------------------------------------------------------- /test/unit/poll_serializer/count_per_month_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class PollSerializerTest < MiniTest::Test 4 | include FactoryGirl::Syntax::Methods 5 | 6 | attr_reader :poll 7 | 8 | def setup 9 | @poll = create :full_poll, replies_count: 5, questions_count: 5 10 | @stats = PollSerializer.count_per_month(poll) 11 | end 12 | 13 | def test_retrieves_data_in_the_form_of_an_array 14 | assert_includes @stats.keys, :data 15 | end 16 | 17 | def test_polls_per_month_have_numbers 18 | assert_kind_of Numeric, @stats[:data].first 19 | end 20 | 21 | def test_polls_per_month_have_x_axis 22 | assert_equal "Polls per month", @stats.fetch(:x_axis).fetch(:legend) 23 | end 24 | 25 | def test_polls_per_month_have_x_axis_series 26 | assert_kind_of Array, @stats.fetch(:x_axis).fetch(:series) 27 | end 28 | 29 | def test_polls_per_month_have_x_axis_series_in_proper_format 30 | assert_includes @stats.fetch(:x_axis).fetch(:series).first, Time.now.strftime("%b %Y") 31 | end 32 | 33 | def test_polls_per_month_have_y_axis 34 | assert_equal "No. polls", @stats.fetch(:y_axis).fetch(:legend) 35 | end 36 | 37 | def test_polls_per_month_have_y_axis_max_range 38 | assert_equal 0, @stats.fetch(:y_axis).fetch(:scale)[0] 39 | end 40 | 41 | def test_polls_per_month_have_y_axis_max_range 42 | assert_equal 6, @stats.fetch(:y_axis).fetch(:scale)[1] 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /test/controllers/questions_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class QuestionsControllerTest < ActionDispatch::IntegrationTest 4 | setup do 5 | @question = questions(:one) 6 | end 7 | 8 | test "should get index" do 9 | get questions_url 10 | assert_response :success 11 | end 12 | 13 | test "should get new" do 14 | get new_question_url 15 | assert_response :success 16 | end 17 | 18 | test "should create question" do 19 | assert_difference('Question.count') do 20 | post questions_url, params: { question: { kind: @question.kind, poll_id: @question.poll_id, title: @question.title } } 21 | end 22 | 23 | assert_redirected_to question_url(Question.last) 24 | end 25 | 26 | test "should show question" do 27 | get question_url(@question) 28 | assert_response :success 29 | end 30 | 31 | test "should get edit" do 32 | get edit_question_url(@question) 33 | assert_response :success 34 | end 35 | 36 | test "should update question" do 37 | patch question_url(@question), params: { question: { kind: @question.kind, poll_id: @question.poll_id, title: @question.title } } 38 | assert_redirected_to question_url(@question) 39 | end 40 | 41 | test "should destroy question" do 42 | assert_difference('Question.count', -1) do 43 | delete question_url(@question) 44 | end 45 | 46 | assert_redirected_to questions_url 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /app/assets/javascripts/graph.js: -------------------------------------------------------------------------------- 1 | var Graph = function(selector, data, kind) { 2 | this.selector = selector; 3 | this.data = data; 4 | this.kind = kind; 5 | }; 6 | 7 | Graph.prototype.getData = function() { 8 | var _this = this; 9 | var dataWithCaptions = this.data.data.map(function(element, index, array) { 10 | return [ _this.data.x_axis.series[index], element ]; 11 | }); 12 | 13 | return google.visualization.arrayToDataTable([ 14 | [ this.data.x_axis.legend, this.data.y_axis.legend ], 15 | ].concat(dataWithCaptions)); 16 | }; 17 | 18 | Graph.prototype.render = function() { 19 | var divWidth = $(this.selector).parents(".container:first").prop("clientWidth"); 20 | var chart = new google.visualization[Graph.graphs[this.kind]]($(this.selector)[0]); 21 | var options = { 22 | width: divWidth, 23 | min: 0, 24 | legend: { position: "none" }, 25 | height: 300, 26 | fontName: "sans-serif", 27 | fontSize: "12", 28 | title: this.data.title 29 | }; 30 | 31 | chart.draw(this.getData(), options); 32 | }; 33 | 34 | Graph.instances = []; 35 | 36 | Graph.column = function(selector, data) { 37 | Graph.instances.push(new Graph(selector, data, "column")); 38 | }; 39 | 40 | Graph.pie = function(selector, data) { 41 | Graph.instances.push(new Graph(selector, data, "pie")); 42 | }; 43 | 44 | google.load('visualization', '1.0', {'packages':['corechart']}); 45 | 46 | Graph.graphs = { 47 | "column" : "ColumnChart", 48 | "pie" : "PieChart" 49 | } -------------------------------------------------------------------------------- /app/views/polls/show.html.haml: -------------------------------------------------------------------------------- 1 | %p#notice= flash[:notice] 2 | 3 | %h2 4 | %b 5 | = @poll.title 6 | 7 | = link_to 'Edit', edit_poll_path(@poll), class: "btn btn-default" 8 | \| 9 | = link_to 'Add a question', new_poll_question_path(@poll), class: "btn btn-default" 10 | | 11 | = link_to 'Back', polls_path, class: "btn btn-default" 12 | 13 | 14 | %div 15 | / Nav tabs 16 | %ul.nav.nav-tabs 17 | %li.active 18 | =link_to "Questions", "#tab-questions" , data: {toggle: "tab"} 19 | %li 20 | =link_to "Replies", "#tab-replies" , data: {toggle: "tab"} 21 | %li 22 | =link_to "Stats", "#tab-stats" , data: {toggle: "tab"} 23 | 24 | / Tab panes 25 | .tab-content 26 | #tab-questions.tab-pane.active 27 | %h3 Questions 28 | 29 | %ul 30 | -@poll.questions.each do |question| 31 | %li= question.title 32 | 33 | %ul 34 | -question.possible_answers.each do |possible_answer| 35 | %li=possible_answer.title 36 | 37 | #tab-replies.tab-pane 38 | %h2 Replies 39 | 40 | -@poll.replies.each do |reply| 41 | .col-md-6 42 | .panel.panel-default 43 | .panel-heading.text-right 44 | =time_ago_in_words reply.created_at 45 | .panel-body 46 | %dl 47 | -reply.answers.each do |answer| 48 | %dt=answer.question.title 49 | %dd 50 | =answer.value.present? ? answer.value : answer.possible_answer.title 51 | 52 | 53 | #tab-stats.tab-pane 54 | =render 'stats' -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

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

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

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

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.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 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => 'public, max-age=3600' 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | config.action_mailer.perform_caching = false 31 | 32 | # Tell Action Mailer not to deliver emails to the real world. 33 | # The :test delivery method accumulates sent emails in the 34 | # ActionMailer::Base.deliveries array. 35 | config.action_mailer.delivery_method = :test 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /app/controllers/polls_controller.rb: -------------------------------------------------------------------------------- 1 | class PollsController < ApplicationController 2 | before_action :set_poll, only: [:show, :edit, :update, :destroy] 3 | 4 | # GET /polls 5 | # GET /polls.json 6 | def index 7 | @polls = Poll.all 8 | end 9 | 10 | # GET /polls/1 11 | # GET /polls/1.json 12 | def show 13 | end 14 | 15 | # GET /polls/new 16 | def new 17 | @poll = Poll.new 18 | end 19 | 20 | # GET /polls/1/edit 21 | def edit 22 | end 23 | 24 | # POST /polls 25 | # POST /polls.json 26 | def create 27 | @poll = Poll.new(poll_params) 28 | 29 | respond_to do |format| 30 | if @poll.save 31 | format.html { redirect_to @poll, notice: 'Poll was successfully created.' } 32 | format.json { render :show, status: :created, location: @poll } 33 | else 34 | format.html { render :new } 35 | format.json { render json: @poll.errors, status: :unprocessable_entity } 36 | end 37 | end 38 | end 39 | 40 | # PATCH/PUT /polls/1 41 | # PATCH/PUT /polls/1.json 42 | def update 43 | respond_to do |format| 44 | if @poll.update(poll_params) 45 | format.html { redirect_to @poll, notice: 'Poll was successfully updated.' } 46 | format.json { render :show, status: :ok, location: @poll } 47 | else 48 | format.html { render :edit } 49 | format.json { render json: @poll.errors, status: :unprocessable_entity } 50 | end 51 | end 52 | end 53 | 54 | # DELETE /polls/1 55 | # DELETE /polls/1.json 56 | def destroy 57 | @poll.destroy 58 | respond_to do |format| 59 | format.html { redirect_to polls_url, notice: 'Poll was successfully destroyed.' } 60 | format.json { head :no_content } 61 | end 62 | end 63 | 64 | private 65 | # Use callbacks to share common setup or constraints between actions. 66 | def set_poll 67 | @poll = Poll.find(params[:id]) 68 | end 69 | 70 | # Never trust parameters from the scary internet, only allow the white list through. 71 | def poll_params 72 | params.require(:poll).permit(:title) 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.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 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | if Rails.root.join('tmp/caching-dev.txt').exist? 17 | config.action_controller.perform_caching = true 18 | 19 | config.cache_store = :memory_store 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => 'public, max-age=172800' 22 | } 23 | else 24 | config.action_controller.perform_caching = false 25 | 26 | config.cache_store = :null_store 27 | end 28 | 29 | # Don't care if the mailer can't send. 30 | config.action_mailer.raise_delivery_errors = false 31 | 32 | config.action_mailer.perform_caching = false 33 | 34 | # Print deprecation notices to the Rails logger. 35 | config.active_support.deprecation = :log 36 | 37 | # Raise an error on page load if there are pending migrations. 38 | config.active_record.migration_error = :page_load 39 | 40 | # Debug mode disables concatenation and preprocessing of assets. 41 | # This option may cause significant delays in view rendering with a large 42 | # number of complex assets. 43 | config.assets.debug = true 44 | 45 | # Suppress logger output for asset requests. 46 | config.assets.quiet = true 47 | 48 | # Raises error for missing translations 49 | # config.action_view.raise_on_missing_translations = true 50 | 51 | # Use an evented file watcher to asynchronously detect changes in source code, 52 | # routes, locales, etc. This feature depends on the listen gem. 53 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 54 | end 55 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum, this matches the default thread size of Active Record. 6 | # 7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i 8 | threads threads_count, threads_count 9 | 10 | # Specifies the `port` that Puma will listen on to receive requests, default is 3000. 11 | # 12 | port ENV.fetch("PORT") { 3000 } 13 | 14 | # Specifies the `environment` that Puma will run in. 15 | # 16 | environment ENV.fetch("RAILS_ENV") { "development" } 17 | 18 | # Specifies the number of `workers` to boot in clustered mode. 19 | # Workers are forked webserver processes. If using threads and workers together 20 | # the concurrency of the application would be max `threads` * `workers`. 21 | # Workers do not work on JRuby or Windows (both of which do not support 22 | # processes). 23 | # 24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 25 | 26 | # Use the `preload_app!` method when specifying a `workers` number. 27 | # This directive tells Puma to first boot the application and load code 28 | # before forking the application. This takes advantage of Copy On Write 29 | # process behavior so workers use less memory. If you use this option 30 | # you need to make sure to reconnect any threads in the `on_worker_boot` 31 | # block. 32 | # 33 | # preload_app! 34 | 35 | # The code in the `on_worker_boot` will be called if you are using 36 | # clustered mode by specifying a number of `workers`. After each worker 37 | # process is booted this block will be run, if you are using `preload_app!` 38 | # option you will want to use this block to reconnect to any threads 39 | # or connections that may have been created at application boot, Ruby 40 | # cannot share connections between processes. 41 | # 42 | # on_worker_boot do 43 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) 44 | # end 45 | 46 | # Allow puma to be restarted by `rails restart` command. 47 | plugin :tmp_restart 48 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | git_source(:github) do |repo_name| 4 | repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 | "https://github.com/#{repo_name}.git" 6 | end 7 | 8 | 9 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 10 | gem 'rails', '~> 5.0.2' 11 | # Use sqlite3 as the database for Active Record 12 | gem 'sqlite3' 13 | # Use Puma as the app server 14 | gem 'puma', '~> 3.0' 15 | # Use SCSS for stylesheets 16 | gem 'sass-rails', '~> 5.0' 17 | # Use Uglifier as compressor for JavaScript assets 18 | gem 'uglifier', '>= 1.3.0' 19 | # Use CoffeeScript for .coffee assets and views 20 | gem 'coffee-rails', '~> 4.2' 21 | # See https://github.com/rails/execjs#readme for more supported runtimes 22 | # gem 'therubyracer', platforms: :ruby 23 | 24 | # Use jquery as the JavaScript library 25 | gem 'jquery-rails' 26 | # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 27 | gem 'turbolinks', '~> 5' 28 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 29 | gem 'jbuilder', '~> 2.5' 30 | # Use Redis adapter to run Action Cable in production 31 | # gem 'redis', '~> 3.0' 32 | # Use ActiveModel has_secure_password 33 | # gem 'bcrypt', '~> 3.1.7' 34 | 35 | # Use Capistrano for deployment 36 | # gem 'capistrano-rails', group: :development 37 | 38 | group :development, :test do 39 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 40 | gem 'byebug', platform: :mri 41 | end 42 | 43 | group :development do 44 | # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 45 | gem 'web-console', '>= 3.3.0' 46 | gem 'listen', '~> 3.0.5' 47 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 48 | gem 'spring' 49 | gem 'spring-watcher-listen', '~> 2.0.0' 50 | end 51 | 52 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 53 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 54 | 55 | 56 | gem 'bootstrap-sass' 57 | 58 | gem 'haml-rails' 59 | gem 'pry-rails' 60 | 61 | group :test do 62 | gem 'factory_girl_rails' 63 | gem 'minitest-rails' 64 | end 65 | 66 | group :development do 67 | gem 'html2haml' 68 | end -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 20170415201917) do 14 | 15 | create_table "answers", force: :cascade do |t| 16 | t.integer "reply_id" 17 | t.integer "question_id" 18 | t.integer "possible_answer_id" 19 | t.string "value" 20 | t.datetime "created_at", null: false 21 | t.datetime "updated_at", null: false 22 | t.index ["possible_answer_id"], name: "index_answers_on_possible_answer_id" 23 | t.index ["question_id"], name: "index_answers_on_question_id" 24 | t.index ["reply_id"], name: "index_answers_on_reply_id" 25 | end 26 | 27 | create_table "polls", force: :cascade do |t| 28 | t.string "title" 29 | t.datetime "created_at", null: false 30 | t.datetime "updated_at", null: false 31 | end 32 | 33 | create_table "possible_answers", force: :cascade do |t| 34 | t.integer "question_id" 35 | t.string "title" 36 | t.datetime "created_at", null: false 37 | t.datetime "updated_at", null: false 38 | t.index ["question_id"], name: "index_possible_answers_on_question_id" 39 | end 40 | 41 | create_table "questions", force: :cascade do |t| 42 | t.string "title" 43 | t.string "kind" 44 | t.integer "poll_id" 45 | t.datetime "created_at", null: false 46 | t.datetime "updated_at", null: false 47 | t.index ["poll_id"], name: "index_questions_on_poll_id" 48 | end 49 | 50 | create_table "replies", force: :cascade do |t| 51 | t.integer "poll_id" 52 | t.datetime "created_at", null: false 53 | t.datetime "updated_at", null: false 54 | t.index ["poll_id"], name: "index_replies_on_poll_id" 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /app/controllers/questions_controller.rb: -------------------------------------------------------------------------------- 1 | class QuestionsController < ApplicationController 2 | before_action :set_question, only: [:show, :edit, :update, :destroy] 3 | before_action :set_poll 4 | before_action :set_kind_questions, only: [ :new, :create, :edit, :update ] 5 | 6 | 7 | # GET /questions 8 | # GET /questions.json 9 | def index 10 | @questions = Question.all 11 | end 12 | 13 | # GET /questions/1 14 | # GET /questions/1.json 15 | def show 16 | end 17 | 18 | # GET /questions/new 19 | def new 20 | @question = @poll.questions.build 21 | 5.times { @question.possible_answers.build } 22 | end 23 | 24 | # GET /questions/1/edit 25 | def edit 26 | end 27 | 28 | # POST /questions 29 | # POST /questions.json 30 | def create 31 | @question = @poll.questions.build(question_params) 32 | respond_to do |format| 33 | if @question.save 34 | flash[:notice] = "Question was successfully created." 35 | format.html { redirect_to @poll } 36 | format.json { render :show, status: :created, location: @question } 37 | else 38 | format.html { render :new } 39 | format.json { render json: @question.errors, status: :unprocessable_entity } 40 | end 41 | end 42 | end 43 | 44 | # PATCH/PUT /questions/1 45 | # PATCH/PUT /questions/1.json 46 | def update 47 | respond_to do |format| 48 | if @question.update(question_params) 49 | format.html { redirect_to @question, notice: 'Question was successfully updated.' } 50 | format.json { render :show, status: :ok, location: @question } 51 | else 52 | format.html { render :edit } 53 | format.json { render json: @question.errors, status: :unprocessable_entity } 54 | end 55 | end 56 | end 57 | 58 | # DELETE /questions/1 59 | # DELETE /questions/1.json 60 | def destroy 61 | @question.destroy 62 | respond_to do |format| 63 | format.html { redirect_to 'poll#:poll_id#question', notice: 'Question was successfully destroyed.' } 64 | format.json { head :no_content } 65 | end 66 | end 67 | 68 | private 69 | # Use callbacks to share common setup or constraints between actions. 70 | def set_question 71 | @question = Question.find(params[:id]) 72 | end 73 | 74 | # Never trust parameters from the scary internet, only allow the white list through. 75 | def question_params 76 | params.require(:question).permit(:poll_id, :title, :kind, { possible_answers_attributes: [ :question_id, :title ] } ) 77 | end 78 | 79 | def set_poll 80 | @poll = Poll.find params[:poll_id] 81 | end 82 | 83 | def set_kind_questions 84 | @kind_options = [["Open Answer", "open"], ["Multiple Choice", "choice"]] 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.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 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Disable serving static files from the `/public` folder by default since 18 | # Apache or NGINX already handles this. 19 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 20 | 21 | # Compress JavaScripts and CSS. 22 | config.assets.js_compressor = :uglifier 23 | # config.assets.css_compressor = :sass 24 | 25 | # Do not fallback to assets pipeline if a precompiled asset is missed. 26 | config.assets.compile = false 27 | 28 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 29 | 30 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 31 | # config.action_controller.asset_host = 'http://assets.example.com' 32 | 33 | # Specifies the header that your server uses for sending files. 34 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 35 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 36 | 37 | # Mount Action Cable outside main process or domain 38 | # config.action_cable.mount_path = nil 39 | # config.action_cable.url = 'wss://example.com/cable' 40 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Use the lowest log level to ensure availability of diagnostic information 46 | # when problems arise. 47 | config.log_level = :debug 48 | 49 | # Prepend all log lines with the following tags. 50 | config.log_tags = [ :request_id ] 51 | 52 | # Use a different cache store in production. 53 | # config.cache_store = :mem_cache_store 54 | 55 | # Use a real queuing backend for Active Job (and separate queues per environment) 56 | # config.active_job.queue_adapter = :resque 57 | # config.active_job.queue_name_prefix = "aniketpoll_#{Rails.env}" 58 | config.action_mailer.perform_caching = false 59 | 60 | # Ignore bad email addresses and do not raise email delivery errors. 61 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 62 | # config.action_mailer.raise_delivery_errors = false 63 | 64 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 65 | # the I18n.default_locale when a translation cannot be found). 66 | config.i18n.fallbacks = true 67 | 68 | # Send deprecation notices to registered listeners. 69 | config.active_support.deprecation = :notify 70 | 71 | # Use default logging formatter so that PID and timestamp are not suppressed. 72 | config.log_formatter = ::Logger::Formatter.new 73 | 74 | # Use a different logger for distributed setups. 75 | # require 'syslog/logger' 76 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 77 | 78 | if ENV["RAILS_LOG_TO_STDOUT"].present? 79 | logger = ActiveSupport::Logger.new(STDOUT) 80 | logger.formatter = config.log_formatter 81 | config.logger = ActiveSupport::TaggedLogging.new(logger) 82 | end 83 | 84 | # Do not dump schema after migrations. 85 | config.active_record.dump_schema_after_migration = false 86 | end 87 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.0.2) 5 | actionpack (= 5.0.2) 6 | nio4r (>= 1.2, < 3.0) 7 | websocket-driver (~> 0.6.1) 8 | actionmailer (5.0.2) 9 | actionpack (= 5.0.2) 10 | actionview (= 5.0.2) 11 | activejob (= 5.0.2) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.0.2) 15 | actionview (= 5.0.2) 16 | activesupport (= 5.0.2) 17 | rack (~> 2.0) 18 | rack-test (~> 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.0.2) 22 | activesupport (= 5.0.2) 23 | builder (~> 3.1) 24 | erubis (~> 2.7.0) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 | activejob (5.0.2) 28 | activesupport (= 5.0.2) 29 | globalid (>= 0.3.6) 30 | activemodel (5.0.2) 31 | activesupport (= 5.0.2) 32 | activerecord (5.0.2) 33 | activemodel (= 5.0.2) 34 | activesupport (= 5.0.2) 35 | arel (~> 7.0) 36 | activesupport (5.0.2) 37 | concurrent-ruby (~> 1.0, >= 1.0.2) 38 | i18n (~> 0.7) 39 | minitest (~> 5.1) 40 | tzinfo (~> 1.1) 41 | arel (7.1.4) 42 | autoprefixer-rails (6.7.7.2) 43 | execjs 44 | bindex (0.5.0) 45 | bootstrap-sass (3.3.7) 46 | autoprefixer-rails (>= 5.2.1) 47 | sass (>= 3.3.4) 48 | builder (3.2.3) 49 | byebug (9.0.6) 50 | coderay (1.1.1) 51 | coffee-rails (4.2.1) 52 | coffee-script (>= 2.2.0) 53 | railties (>= 4.0.0, < 5.2.x) 54 | coffee-script (2.4.1) 55 | coffee-script-source 56 | execjs 57 | coffee-script-source (1.12.2) 58 | concurrent-ruby (1.0.5) 59 | erubis (2.7.0) 60 | execjs (2.7.0) 61 | factory_girl (4.8.0) 62 | activesupport (>= 3.0.0) 63 | factory_girl_rails (4.8.0) 64 | factory_girl (~> 4.8.0) 65 | railties (>= 3.0.0) 66 | ffi (1.9.18) 67 | globalid (0.4.0) 68 | activesupport (>= 4.2.0) 69 | haml (4.0.7) 70 | tilt 71 | haml-rails (0.9.0) 72 | actionpack (>= 4.0.1) 73 | activesupport (>= 4.0.1) 74 | haml (>= 4.0.6, < 5.0) 75 | html2haml (>= 1.0.1) 76 | railties (>= 4.0.1) 77 | html2haml (2.1.0) 78 | erubis (~> 2.7.0) 79 | haml (~> 4.0) 80 | nokogiri (>= 1.6.0) 81 | ruby_parser (~> 3.5) 82 | i18n (0.8.1) 83 | jbuilder (2.6.3) 84 | activesupport (>= 3.0.0, < 5.2) 85 | multi_json (~> 1.2) 86 | jquery-rails (4.3.1) 87 | rails-dom-testing (>= 1, < 3) 88 | railties (>= 4.2.0) 89 | thor (>= 0.14, < 2.0) 90 | listen (3.0.8) 91 | rb-fsevent (~> 0.9, >= 0.9.4) 92 | rb-inotify (~> 0.9, >= 0.9.7) 93 | loofah (2.0.3) 94 | nokogiri (>= 1.5.9) 95 | mail (2.6.4) 96 | mime-types (>= 1.16, < 4) 97 | method_source (0.8.2) 98 | mime-types (3.1) 99 | mime-types-data (~> 3.2015) 100 | mime-types-data (3.2016.0521) 101 | mini_portile2 (2.1.0) 102 | minitest (5.10.1) 103 | minitest-rails (3.0.0) 104 | minitest (~> 5.8) 105 | railties (~> 5.0) 106 | multi_json (1.12.1) 107 | nio4r (2.0.0) 108 | nokogiri (1.7.1) 109 | mini_portile2 (~> 2.1.0) 110 | pry (0.10.4) 111 | coderay (~> 1.1.0) 112 | method_source (~> 0.8.1) 113 | slop (~> 3.4) 114 | pry-rails (0.3.6) 115 | pry (>= 0.10.4) 116 | puma (3.8.2) 117 | rack (2.0.1) 118 | rack-test (0.6.3) 119 | rack (>= 1.0) 120 | rails (5.0.2) 121 | actioncable (= 5.0.2) 122 | actionmailer (= 5.0.2) 123 | actionpack (= 5.0.2) 124 | actionview (= 5.0.2) 125 | activejob (= 5.0.2) 126 | activemodel (= 5.0.2) 127 | activerecord (= 5.0.2) 128 | activesupport (= 5.0.2) 129 | bundler (>= 1.3.0, < 2.0) 130 | railties (= 5.0.2) 131 | sprockets-rails (>= 2.0.0) 132 | rails-dom-testing (2.0.2) 133 | activesupport (>= 4.2.0, < 6.0) 134 | nokogiri (~> 1.6) 135 | rails-html-sanitizer (1.0.3) 136 | loofah (~> 2.0) 137 | railties (5.0.2) 138 | actionpack (= 5.0.2) 139 | activesupport (= 5.0.2) 140 | method_source 141 | rake (>= 0.8.7) 142 | thor (>= 0.18.1, < 2.0) 143 | rake (12.0.0) 144 | rb-fsevent (0.9.8) 145 | rb-inotify (0.9.8) 146 | ffi (>= 0.5.0) 147 | ruby_parser (3.9.0) 148 | sexp_processor (~> 4.1) 149 | sass (3.4.23) 150 | sass-rails (5.0.6) 151 | railties (>= 4.0.0, < 6) 152 | sass (~> 3.1) 153 | sprockets (>= 2.8, < 4.0) 154 | sprockets-rails (>= 2.0, < 4.0) 155 | tilt (>= 1.1, < 3) 156 | sexp_processor (4.9.0) 157 | slop (3.6.0) 158 | spring (2.0.1) 159 | activesupport (>= 4.2) 160 | spring-watcher-listen (2.0.1) 161 | listen (>= 2.7, < 4.0) 162 | spring (>= 1.2, < 3.0) 163 | sprockets (3.7.1) 164 | concurrent-ruby (~> 1.0) 165 | rack (> 1, < 3) 166 | sprockets-rails (3.2.0) 167 | actionpack (>= 4.0) 168 | activesupport (>= 4.0) 169 | sprockets (>= 3.0.0) 170 | sqlite3 (1.3.13) 171 | thor (0.19.4) 172 | thread_safe (0.3.6) 173 | tilt (2.0.7) 174 | turbolinks (5.0.1) 175 | turbolinks-source (~> 5) 176 | turbolinks-source (5.0.0) 177 | tzinfo (1.2.3) 178 | thread_safe (~> 0.1) 179 | uglifier (3.2.0) 180 | execjs (>= 0.3.0, < 3) 181 | web-console (3.5.0) 182 | actionview (>= 5.0) 183 | activemodel (>= 5.0) 184 | bindex (>= 0.4.0) 185 | railties (>= 5.0) 186 | websocket-driver (0.6.5) 187 | websocket-extensions (>= 0.1.0) 188 | websocket-extensions (0.1.2) 189 | 190 | PLATFORMS 191 | ruby 192 | 193 | DEPENDENCIES 194 | bootstrap-sass 195 | byebug 196 | coffee-rails (~> 4.2) 197 | factory_girl_rails 198 | haml-rails 199 | html2haml 200 | jbuilder (~> 2.5) 201 | jquery-rails 202 | listen (~> 3.0.5) 203 | minitest-rails 204 | pry-rails 205 | puma (~> 3.0) 206 | rails (~> 5.0.2) 207 | sass-rails (~> 5.0) 208 | spring 209 | spring-watcher-listen (~> 2.0.0) 210 | sqlite3 211 | turbolinks (~> 5) 212 | tzinfo-data 213 | uglifier (>= 1.3.0) 214 | web-console (>= 3.3.0) 215 | 216 | BUNDLED WITH 217 | 1.14.6 218 | --------------------------------------------------------------------------------