├── 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 |If you are the application owner check the logs for more information.
64 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |