schemer_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/schemer/application.js +15 -0
- data/app/assets/stylesheets/schemer/application.css +15 -0
- data/app/controllers/schemer/application_controller.rb +4 -0
- data/app/controllers/schemer/surveys_controller.rb +62 -0
- data/app/helpers/schemer/application_helper.rb +4 -0
- data/app/models/schemer/answer.rb +9 -0
- data/app/models/schemer/concerns/surveyor.rb +33 -0
- data/app/models/schemer/option.rb +7 -0
- data/app/models/schemer/question.rb +11 -0
- data/app/models/schemer/survey.rb +11 -0
- data/app/models/schemer/surveyor.rb +9 -0
- data/app/serializers/schemer/option_serializer.rb +5 -0
- data/app/serializers/schemer/question_serializer.rb +12 -0
- data/app/serializers/schemer/survey_serializer.rb +11 -0
- data/app/views/layouts/schemer/application.html.erb +14 -0
- data/app/views/schemer/surveys/_form.html.erb +42 -0
- data/app/views/schemer/surveys/_option_fields.html.erb +11 -0
- data/app/views/schemer/surveys/_question_fields.html.erb +19 -0
- data/app/views/schemer/surveys/edit.html.erb +6 -0
- data/app/views/schemer/surveys/index.html.erb +31 -0
- data/app/views/schemer/surveys/new.html.erb +5 -0
- data/app/views/schemer/surveys/show.html.erb +27 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20140922114934_create_schemer_surveys.rb +12 -0
- data/db/migrate/20140924092329_create_schemer_questions.rb +10 -0
- data/db/migrate/20140924100930_create_schemer_options.rb +10 -0
- data/db/migrate/20140924113459_create_schemer_surveyors.rb +10 -0
- data/db/migrate/20140925070034_create_schemer_answers.rb +11 -0
- data/lib/schemer.rb +6 -0
- data/lib/schemer/acts_as_surveyor.rb +51 -0
- data/lib/schemer/engine.rb +18 -0
- data/lib/schemer/version.rb +3 -0
- data/lib/tasks/schemer_tasks.rake +4 -0
- data/spec/controllers/schemer/surveys_controller_spec.rb +162 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20140924120804_create_users.rb +10 -0
- data/spec/dummy/db/schema.rb +65 -0
- data/spec/dummy/log/development.log +6651 -0
- data/spec/dummy/log/test.log +5257 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/factories/users.rb +8 -0
- data/spec/dummy/spec/models/user_spec.rb +53 -0
- data/spec/dummy/spec/spec_helper.rb +40 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/00b35f525e37a6602da315f4d5e665dc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0f1b7dae5a45908f12d8a85ec2dea265 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1cae3a1cfbf20f6d3388e4f0df72e604 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/67ec2eedb1bf19ebac485395204d5ec8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6f4031d9ad6e5d190cebb22f3914014d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/771fe04d90b165a3212f1f502e6cee9c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/90f32837697f85e5ab9eb8f474b24ce7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b05e2fa6f1b28a61b4327f446cb75a8c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b711b2b6c927435f89e55ef8cbfd6f16 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bf73041cb847de60775d7af6a47b0b7b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c63d712d76a93f6ce39982306770d356 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffa59ac01b389e4255c64638fc2885b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e5ae4857694c81f01b2035047707ab71 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ed548c7d884e98d8f26294a43e53d139 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f0e8def7b8807216809294cc60790679 +0 -0
- data/spec/factories/schemer_answers.rb +9 -0
- data/spec/factories/schemer_options.rb +8 -0
- data/spec/factories/schemer_questions.rb +8 -0
- data/spec/factories/schemer_surveyors.rb +7 -0
- data/spec/factories/schemer_surveys.rb +10 -0
- data/spec/models/schemer/answer_spec.rb +11 -0
- data/spec/models/schemer/option_spec.rb +9 -0
- data/spec/models/schemer/question_spec.rb +11 -0
- data/spec/models/schemer/survey_spec.rb +42 -0
- data/spec/models/schemer/surveyor_spec.rb +45 -0
- data/spec/routing/schemer/surveys_routing_spec.rb +39 -0
- data/spec/spec_helper.rb +40 -0
- metadata +387 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1363cff8a13a68db2bfb1f0c8af5f8e1b9b0965
|
4
|
+
data.tar.gz: cecff424f61f3f6e42b6b2b206475770f945815a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74db4db332b0db4f432fd8fca55c51cdc02f8d1b5bab767dd8a0a3528217678d264ea1d93cb06bdaae75e687f9545894064baaa7bd0769807c86a491019a57c9
|
7
|
+
data.tar.gz: 6d19425dfe5d04287b00c4444b5417f3a1763c187049b0e16a12cbefb6cecd28847e21c4a1eddb7f7cc6ca40fdf93c81f76b76f95bdb1b7c9439e84ba8785633
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Schemer'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rspec/core'
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
|
27
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
28
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
29
|
+
|
30
|
+
task :default => :spec
|
@@ -0,0 +1,15 @@
|
|
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 vendor/assets/javascripts of plugins, if any, 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.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require cocoon
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_dependency "schemer/application_controller"
|
2
|
+
|
3
|
+
module Schemer
|
4
|
+
class SurveysController < ApplicationController
|
5
|
+
before_action :set_survey, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /surveys
|
8
|
+
def index
|
9
|
+
@surveys = Survey.all
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /surveys/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /surveys/new
|
17
|
+
def new
|
18
|
+
@survey = Survey.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /surveys/1/edit
|
22
|
+
def edit
|
23
|
+
end
|
24
|
+
|
25
|
+
# POST /surveys
|
26
|
+
def create
|
27
|
+
@survey = Survey.new(survey_params)
|
28
|
+
|
29
|
+
if @survey.save
|
30
|
+
redirect_to @survey, notice: 'Survey was successfully created.'
|
31
|
+
else
|
32
|
+
render :new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# PATCH/PUT /surveys/1
|
37
|
+
def update
|
38
|
+
if @survey.update(survey_params)
|
39
|
+
redirect_to @survey, notice: 'Survey was successfully updated.'
|
40
|
+
else
|
41
|
+
render :edit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# DELETE /surveys/1
|
46
|
+
def destroy
|
47
|
+
@survey.destroy
|
48
|
+
redirect_to surveys_url, notice: 'Survey was successfully destroyed.'
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
# Use callbacks to share common setup or constraints between actions.
|
53
|
+
def set_survey
|
54
|
+
@survey = Survey.find(params[:id])
|
55
|
+
end
|
56
|
+
|
57
|
+
# Only allow a trusted parameter "white list" through.
|
58
|
+
def survey_params
|
59
|
+
params.require(:survey).permit(:title, :description, :is_started, :is_complete, questions_attributes: [:id, :title, :_destroy, options_attributes: [:id, :title, :_destroy]])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# module Schemer
|
2
|
+
# module Concerns
|
3
|
+
# module Surveyor
|
4
|
+
|
5
|
+
# extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# module ClassMethods
|
8
|
+
# def acts_as_surveyor(options={})
|
9
|
+
# include Schemer::Concerns::Surveyor::LocalInstanceMethods
|
10
|
+
|
11
|
+
# class << self
|
12
|
+
# def test
|
13
|
+
# "test"
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
|
19
|
+
# module LocalInstanceMethods
|
20
|
+
# def squawk
|
21
|
+
# "hello"
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
|
25
|
+
# included do |receiver|
|
26
|
+
# has_many :feedbacks, :as => :surveyable
|
27
|
+
# end
|
28
|
+
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
# ActiveRecord::Base.send :include, ::Schemer::Concerns::Surveyor
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Schemer
|
2
|
+
class Question < ActiveRecord::Base
|
3
|
+
attr_accessible :title, :options_attributes
|
4
|
+
|
5
|
+
belongs_to :survey
|
6
|
+
has_many :options
|
7
|
+
has_one :answer
|
8
|
+
|
9
|
+
accepts_nested_attributes_for :options, :reject_if => :all_blank, :allow_destroy => true
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Schemer
|
2
|
+
class Survey < ActiveRecord::Base
|
3
|
+
attr_accessible :description, :title, :questions_attributes
|
4
|
+
|
5
|
+
has_many :questions
|
6
|
+
has_many :surveyors
|
7
|
+
|
8
|
+
accepts_nested_attributes_for :questions, :reject_if => :all_blank, :allow_destroy => true
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Schemer</title>
|
5
|
+
<%= stylesheet_link_tag "schemer/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "schemer/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<%= form_for(@survey) do |f| %>
|
2
|
+
<% if @survey.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@survey.errors.count, "error") %> prohibited this survey from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @survey.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br>
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :description %><br>
|
20
|
+
<%= f.text_area :description %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :is_started %><br>
|
24
|
+
<%= f.check_box :is_started %>
|
25
|
+
</div>
|
26
|
+
<div class="field">
|
27
|
+
<%= f.label :is_complete %><br>
|
28
|
+
<%= f.check_box :is_complete %>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<%= f.fields_for :questions do |question| %>
|
32
|
+
<%= render 'question_fields', :f => question %>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<div class="q">
|
36
|
+
<%= link_to_add_association 'add question', f, :questions %>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div class="actions">
|
40
|
+
<%= f.submit %>
|
41
|
+
</div>
|
42
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<div class="nested-fields">
|
2
|
+
<h2>Question</h2>
|
3
|
+
<div class="field">
|
4
|
+
<%= f.label :title %><br>
|
5
|
+
<%= f.text_field :title %>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<%= f.fields_for :options do |option| %>
|
9
|
+
<%= render 'option_fields', :f => option %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div class="q">
|
13
|
+
<%= link_to_add_association 'add option', f, :options %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
|
17
|
+
<%= link_to_remove_association "remove question", f %>
|
18
|
+
|
19
|
+
</div>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<h1>Listing surveys</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Title</th>
|
7
|
+
<th>Description</th>
|
8
|
+
<th>Is started</th>
|
9
|
+
<th>Is complete</th>
|
10
|
+
<th colspan="3"></th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
|
14
|
+
<tbody>
|
15
|
+
<% @surveys.each do |survey| %>
|
16
|
+
<tr>
|
17
|
+
<td><%= survey.title %></td>
|
18
|
+
<td><%= survey.description %></td>
|
19
|
+
<td><%= survey.is_started %></td>
|
20
|
+
<td><%= survey.is_complete %></td>
|
21
|
+
<td><%= link_to 'Show', survey %></td>
|
22
|
+
<td><%= link_to 'Edit', schemer.edit_survey_path(survey) %></td>
|
23
|
+
<td><%= link_to 'Destroy', survey, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
<br>
|
30
|
+
|
31
|
+
<%= link_to 'New Survey', schemer.new_survey_path %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Title:</strong>
|
5
|
+
<%= @survey.title %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Description:</strong>
|
10
|
+
<%= @survey.description %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<h3>Questions:</h3>
|
14
|
+
<% @survey.questions.each_with_index do |question, index| %>
|
15
|
+
<p>
|
16
|
+
Question <%= index + 1 %>: <%= question.title %>
|
17
|
+
|
18
|
+
<% question.options.each_with_index do |option, index| %>
|
19
|
+
<p>
|
20
|
+
Option <%= index + 1 %>: <%= option.title %>
|
21
|
+
</p>
|
22
|
+
<% end %>
|
23
|
+
</p>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<%= link_to 'Edit', schemer.edit_survey_path(@survey) %> |
|
27
|
+
<%= link_to 'Back', schemer.surveys_path %>
|