schemer_rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/config/routes.rb
ADDED
data/lib/schemer.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Schemer
|
|
2
|
+
module ActsAsSurveyor
|
|
3
|
+
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
module ClassMethods
|
|
7
|
+
def acts_as_surveyor(options={})
|
|
8
|
+
include Schemer::ActsAsSurveyor::LocalInstanceMethods
|
|
9
|
+
|
|
10
|
+
has_many :feedbacks,
|
|
11
|
+
:class_name => "::Schemer::Surveyor",
|
|
12
|
+
:as => :surveyable
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def test
|
|
16
|
+
"test"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module LocalInstanceMethods
|
|
23
|
+
def list_all_surveys
|
|
24
|
+
::Schemer::Survey.all
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def list_incomplete_surveys
|
|
28
|
+
::Schemer::Survey.joins("LEFT JOIN schemer_surveyors ON schemer_surveyors.survey_id = schemer_surveys.id").where("(schemer_surveyors.surveyable_id IS NULL) OR (schemer_surveyors.surveyable_id != ? AND schemer_surveyors.surveyable_type = ?)", self.id, self.class.name)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def list_all_surveys_by_name
|
|
32
|
+
list_all_surveys.map(&:name)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def list_all_survey_questions(survey)
|
|
36
|
+
survey.questions
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def mark_survey_question(question, option)
|
|
40
|
+
# create an answer record for surveyor record
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def squawk
|
|
44
|
+
"hello"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ActiveRecord::Base.send :include, ::Schemer::ActsAsSurveyor
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'protected_attributes'
|
|
2
|
+
require 'cocoon'
|
|
3
|
+
require 'jquery-rails'
|
|
4
|
+
require 'active_model_serializers'
|
|
5
|
+
|
|
6
|
+
module Schemer
|
|
7
|
+
class Engine < ::Rails::Engine
|
|
8
|
+
isolate_namespace Schemer
|
|
9
|
+
|
|
10
|
+
config.generators do |g|
|
|
11
|
+
g.test_framework :rspec, :fixture => false
|
|
12
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
|
13
|
+
g.assets false
|
|
14
|
+
g.helper false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
|
4
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
|
6
|
+
#
|
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
|
9
|
+
# controller code, this generated spec may or may not pass.
|
|
10
|
+
#
|
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
|
14
|
+
#
|
|
15
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
|
19
|
+
# that an instance is receiving a specific message.
|
|
20
|
+
|
|
21
|
+
module Schemer
|
|
22
|
+
describe SurveysController do
|
|
23
|
+
routes { Schemer::Engine.routes }
|
|
24
|
+
# This should return the minimal set of attributes required to create a valid
|
|
25
|
+
# Survey. As you add validations to Survey, be sure to
|
|
26
|
+
# adjust the attributes here as well.
|
|
27
|
+
let(:valid_attributes) { { "title" => "MyString" } }
|
|
28
|
+
|
|
29
|
+
# This should return the minimal set of values that should be in the session
|
|
30
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
31
|
+
# SurveysController. Be sure to keep this updated too.
|
|
32
|
+
let(:valid_session) { {} }
|
|
33
|
+
|
|
34
|
+
describe "GET index" do
|
|
35
|
+
it "assigns all surveys as @surveys" do
|
|
36
|
+
survey = Survey.create! valid_attributes
|
|
37
|
+
get :index, {}, valid_session
|
|
38
|
+
assigns(:surveys).should eq([survey])
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "GET show" do
|
|
43
|
+
it "assigns the requested survey as @survey" do
|
|
44
|
+
survey = Survey.create! valid_attributes
|
|
45
|
+
get :show, {:id => survey.to_param}, valid_session
|
|
46
|
+
assigns(:survey).should eq(survey)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "GET new" do
|
|
51
|
+
it "assigns a new survey as @survey" do
|
|
52
|
+
get :new, {}, valid_session
|
|
53
|
+
assigns(:survey).should be_a_new(Survey)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe "GET edit" do
|
|
58
|
+
it "assigns the requested survey as @survey" do
|
|
59
|
+
survey = Survey.create! valid_attributes
|
|
60
|
+
get :edit, {:id => survey.to_param}, valid_session
|
|
61
|
+
assigns(:survey).should eq(survey)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "POST create" do
|
|
66
|
+
describe "with valid params" do
|
|
67
|
+
it "creates a new Survey" do
|
|
68
|
+
expect {
|
|
69
|
+
post :create, {:survey => valid_attributes}, valid_session
|
|
70
|
+
}.to change(Survey, :count).by(1)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "assigns a newly created survey as @survey" do
|
|
74
|
+
post :create, {:survey => valid_attributes}, valid_session
|
|
75
|
+
assigns(:survey).should be_a(Survey)
|
|
76
|
+
assigns(:survey).should be_persisted
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "redirects to the created survey" do
|
|
80
|
+
post :create, {:survey => valid_attributes}, valid_session
|
|
81
|
+
response.should redirect_to(Survey.last)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "with invalid params" do
|
|
86
|
+
it "assigns a newly created but unsaved survey as @survey" do
|
|
87
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
88
|
+
Survey.any_instance.stub(:save).and_return(false)
|
|
89
|
+
post :create, {:survey => { "title" => "invalid value" }}, valid_session
|
|
90
|
+
assigns(:survey).should be_a_new(Survey)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "re-renders the 'new' template" do
|
|
94
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
95
|
+
Survey.any_instance.stub(:save).and_return(false)
|
|
96
|
+
post :create, {:survey => { "title" => "invalid value" }}, valid_session
|
|
97
|
+
response.should render_template("new")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe "PUT update" do
|
|
103
|
+
describe "with valid params" do
|
|
104
|
+
it "updates the requested survey" do
|
|
105
|
+
survey = Survey.create! valid_attributes
|
|
106
|
+
# Assuming there are no other surveys in the database, this
|
|
107
|
+
# specifies that the Survey created on the previous line
|
|
108
|
+
# receives the :update_attributes message with whatever params are
|
|
109
|
+
# submitted in the request.
|
|
110
|
+
Survey.any_instance.should_receive(:update).with({ "title" => "MyString" })
|
|
111
|
+
put :update, {:id => survey.to_param, :survey => { "title" => "MyString" }}, valid_session
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "assigns the requested survey as @survey" do
|
|
115
|
+
survey = Survey.create! valid_attributes
|
|
116
|
+
put :update, {:id => survey.to_param, :survey => valid_attributes}, valid_session
|
|
117
|
+
assigns(:survey).should eq(survey)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "redirects to the survey" do
|
|
121
|
+
survey = Survey.create! valid_attributes
|
|
122
|
+
put :update, {:id => survey.to_param, :survey => valid_attributes}, valid_session
|
|
123
|
+
response.should redirect_to(survey)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "with invalid params" do
|
|
128
|
+
it "assigns the survey as @survey" do
|
|
129
|
+
survey = Survey.create! valid_attributes
|
|
130
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
131
|
+
Survey.any_instance.stub(:save).and_return(false)
|
|
132
|
+
put :update, {:id => survey.to_param, :survey => { "title" => "invalid value" }}, valid_session
|
|
133
|
+
assigns(:survey).should eq(survey)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "re-renders the 'edit' template" do
|
|
137
|
+
survey = Survey.create! valid_attributes
|
|
138
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
139
|
+
Survey.any_instance.stub(:save).and_return(false)
|
|
140
|
+
put :update, {:id => survey.to_param, :survey => { "title" => "invalid value" }}, valid_session
|
|
141
|
+
response.should render_template("edit")
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe "DELETE destroy" do
|
|
147
|
+
it "destroys the requested survey" do
|
|
148
|
+
survey = Survey.create! valid_attributes
|
|
149
|
+
expect {
|
|
150
|
+
delete :destroy, {:id => survey.to_param}, valid_session
|
|
151
|
+
}.to change(Survey, :count).by(-1)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "redirects to the surveys list" do
|
|
155
|
+
survey = Survey.create! valid_attributes
|
|
156
|
+
delete :destroy, {:id => survey.to_param}, valid_session
|
|
157
|
+
response.should redirect_to(surveys_path)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
end
|
|
162
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
|
|
26
|
+
|
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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_tree .
|
|
@@ -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,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Dummy</title>
|
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED