reviewable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/javascripts/reviewable/application.js +13 -0
  6. data/app/assets/stylesheets/reviewable/application.css +15 -0
  7. data/app/controllers/reviewable/questions_controller.rb +58 -0
  8. data/app/controllers/reviewable/reviewable_controller.rb +5 -0
  9. data/app/controllers/reviewable/reviews_controller.rb +58 -0
  10. data/app/helpers/reviewable/application_helper.rb +4 -0
  11. data/app/models/reviewable/question.rb +37 -0
  12. data/app/models/reviewable/review.rb +24 -0
  13. data/app/views/layouts/reviewable/application.html.erb +14 -0
  14. data/app/views/reviewable/questions/_form.html.erb +28 -0
  15. data/app/views/reviewable/questions/_question.html.erb +10 -0
  16. data/app/views/reviewable/questions/_question.json.jbuilder +10 -0
  17. data/app/views/reviewable/questions/edit.html.erb +3 -0
  18. data/app/views/reviewable/questions/index.html.erb +21 -0
  19. data/app/views/reviewable/questions/index.json.jbuilder +5 -0
  20. data/app/views/reviewable/questions/new.html.erb +3 -0
  21. data/config/routes.rb +3 -0
  22. data/db/migrate/20141013142401_enable_uuid_ossp_extension.rb +7 -0
  23. data/db/migrate/20141013142552_create_reviewable_reviews.rb +15 -0
  24. data/db/migrate/20141013145632_create_reviewable_questions.rb +15 -0
  25. data/lib/reviewable.rb +4 -0
  26. data/lib/reviewable/acts_as_reviewable.rb +25 -0
  27. data/lib/reviewable/engine.rb +22 -0
  28. data/lib/reviewable/version.rb +3 -0
  29. data/lib/tasks/reviewable_tasks.rake +4 -0
  30. data/spec/dummy/README.rdoc +28 -0
  31. data/spec/dummy/Rakefile +6 -0
  32. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  34. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  35. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  36. data/spec/dummy/app/models/product.rb +4 -0
  37. data/spec/dummy/app/models/user.rb +2 -0
  38. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/spec/dummy/bin/bundle +3 -0
  40. data/spec/dummy/bin/rails +4 -0
  41. data/spec/dummy/bin/rake +4 -0
  42. data/spec/dummy/config.ru +4 -0
  43. data/spec/dummy/config/application.rb +23 -0
  44. data/spec/dummy/config/boot.rb +5 -0
  45. data/spec/dummy/config/database.yml +85 -0
  46. data/spec/dummy/config/environment.rb +5 -0
  47. data/spec/dummy/config/environments/development.rb +37 -0
  48. data/spec/dummy/config/environments/production.rb +78 -0
  49. data/spec/dummy/config/environments/test.rb +39 -0
  50. data/spec/dummy/config/initializers/assets.rb +8 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  53. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  54. data/spec/dummy/config/initializers/inflections.rb +16 -0
  55. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  56. data/spec/dummy/config/initializers/session_store.rb +3 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +23 -0
  59. data/spec/dummy/config/routes.rb +4 -0
  60. data/spec/dummy/config/secrets.yml +22 -0
  61. data/spec/dummy/db/development.sqlite3 +0 -0
  62. data/spec/dummy/db/migrate/20141013173317_create_products.rb +9 -0
  63. data/spec/dummy/db/migrate/20141013174327_create_users.rb +9 -0
  64. data/spec/dummy/db/schema.rb +56 -0
  65. data/spec/dummy/log/development.log +256 -0
  66. data/spec/dummy/log/test.log +41431 -0
  67. data/spec/dummy/public/404.html +67 -0
  68. data/spec/dummy/public/422.html +67 -0
  69. data/spec/dummy/public/500.html +66 -0
  70. data/spec/dummy/public/favicon.ico +0 -0
  71. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  72. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  73. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  74. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  75. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  76. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  77. data/spec/dummy/tmp/capybara/capybara-201410141638119443873212.html +24 -0
  78. data/spec/dummy/tmp/capybara/capybara-201410141807209663577120.html +34 -0
  79. data/spec/dummy/tmp/capybara/capybara-201410141808528516645046.html +34 -0
  80. data/spec/dummy/tmp/capybara/capybara-201410141809478831156886.html +34 -0
  81. data/spec/dummy/tmp/capybara/capybara-201410141811022811314427.html +34 -0
  82. data/spec/dummy/tmp/capybara/capybara-201410141813201391325985.html +34 -0
  83. data/spec/dummy/tmp/capybara/capybara-201410141855296114330585.html +86 -0
  84. data/spec/dummy/tmp/capybara/capybara-201410141857326053813040.html +34 -0
  85. data/spec/dummy/tmp/capybara/capybara-201410141857482438637842.html +35 -0
  86. data/spec/dummy/tmp/capybara/capybara-201410141858304336368395.html +35 -0
  87. data/spec/dummy/tmp/capybara/capybara-20141014185925908498887.html +86 -0
  88. data/spec/dummy/tmp/capybara/capybara-201410141904184954015862.html +35 -0
  89. data/spec/dummy/tmp/capybara/capybara-201410141905062396116920.html +46 -0
  90. data/spec/dummy/tmp/capybara/capybara-201410141905261123020644.html +46 -0
  91. data/spec/factories/product.rb +7 -0
  92. data/spec/factories/question.rb +25 -0
  93. data/spec/factories/review.rb +22 -0
  94. data/spec/factories/user.rb +7 -0
  95. data/spec/features/questions/question_create_spec.rb +43 -0
  96. data/spec/features/questions/question_delete_spec.rb +30 -0
  97. data/spec/features/questions/question_edit_spec.rb +106 -0
  98. data/spec/features/questions/question_index_spec.rb +23 -0
  99. data/spec/models/acts_as_reviewable_spec.rb +12 -0
  100. data/spec/models/reviewable/question_spec.rb +27 -0
  101. data/spec/models/reviewable/review_spec.rb +61 -0
  102. data/spec/rails_helper.rb +60 -0
  103. data/spec/spec_helper.rb +78 -0
  104. metadata +263 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: fec0b53423e9f69ed8b7ddddb26cace4600015b9
4
+ data.tar.gz: 39c56137c223f75f32989c324531932456ea952d
5
+ SHA512:
6
+ metadata.gz: df8d542925ec318ae9bf13ff1fabbbda6f153e5b0b77b88b4cee7af5377bef14d8fea15cb4fb6482e8f0e43453b3efd4c894254df0d661fb142e72e6b8c4cbf1
7
+ data.tar.gz: 194334a873ef41cb228648e5b611b41b6515743e4a74787d25b23fdcccdf77948431087527f74a7ef5e9bd6e168c9245a9254436dcd0c4311ecd28b9799229c7
@@ -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.
@@ -0,0 +1,3 @@
1
+ = Reviewable
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,23 @@
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 = 'Reservable'
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
+
@@ -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,58 @@
1
+ module Reviewable
2
+ class QuestionsController < ReviewableController
3
+ before_filter :load_question, except: :index
4
+
5
+ def index
6
+ @questions = Question.where(true)
7
+ end
8
+
9
+ def new
10
+ end
11
+
12
+ def edit
13
+ end
14
+
15
+ def create
16
+ respond_with @question do |format|
17
+ if @question.update(question_params)
18
+ format.html { redirect_to questions_path, notice: 'Question was successfully created.' }
19
+ else
20
+ format.html { render :new }
21
+ end
22
+ end
23
+ end
24
+
25
+ def update
26
+ respond_with @question do |format|
27
+ if @question.update(question_params)
28
+ format.html { redirect_to questions_path, notice: 'Question was successfully updated.' }
29
+ else
30
+ format.html { render :edit }
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ def destroy
37
+ @question.destroy
38
+ respond_with @question do |format|
39
+ format.html {redirect_to questions_path, notice: 'Question was successfully destroyed.'}
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def question_params
46
+ params.require(:question).permit(:question_text, :question_type, :slug, :answer_min, :answer_max, :enabled, :answer_options_string )
47
+ end
48
+
49
+ def load_question
50
+ if params[:id]
51
+ @question = Question.find(params[:id])
52
+ else
53
+ @question = Question.new
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Reviewable
2
+ class ReviewableController < ApplicationController
3
+ respond_to :html
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ module Reviewable
2
+ class ReviewsController < ReviewableController
3
+ before_filter :load_review, except: :index
4
+
5
+ def index
6
+ @reviews = Review.where(true)
7
+ end
8
+
9
+ def new
10
+ end
11
+
12
+ def edit
13
+ end
14
+
15
+ def create
16
+ respond_with @review do |format|
17
+ if @review.update(review_params)
18
+ format.html { redirect_to reviews_path, notice: 'Review was successfully created.' }
19
+ else
20
+ format.html { render :new }
21
+ end
22
+ end
23
+ end
24
+
25
+ def update
26
+ respond_with @review do |format|
27
+ if @review.update(review_params)
28
+ format.html { redirect_to reviews_path, notice: 'Review was successfully updated.' }
29
+ else
30
+ format.html { render :edit }
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ def destroy
37
+ @review.destroy
38
+ respond_with @review do |format|
39
+ format.html {redirect_to reviews_path, notice: 'Review was successfully destroyed.'}
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def review_params
46
+ params.require(:review).permit(:review_text, :review_type, :slug, :answer_min, :answer_max, :enabled, :answer_options_string )
47
+ end
48
+
49
+ def load_review
50
+ if params[:id]
51
+ @review = Review.find(params[:id])
52
+ else
53
+ @review = Review.new
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ module Reviewable
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,37 @@
1
+ module Reviewable
2
+ class Question < ActiveRecord::Base
3
+ TYPES = ['string', 'integer', 'select', 'text']
4
+
5
+ validates :question_text, :question_type, :slug, presence: true
6
+ validates :slug, uniqueness: true
7
+ validates :question_type, inclusion: TYPES
8
+
9
+ scope :enabled, -> {where(enabled: true)}
10
+
11
+
12
+ # before_validation :build_slug_if_missing
13
+
14
+ before_save :sanitize_answer_options_string
15
+
16
+
17
+ def answer_options
18
+ if answer_options_string
19
+ answer_options_string.split('|').map(&:strip)
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+
28
+ def sanitize_answer_options_string
29
+ self.answer_options_string = answer_options.join('|')
30
+ end
31
+ # def build_slug_if_missing
32
+ # self.slug = question_text.parameterize if slug.blank? && question_text
33
+ # end
34
+
35
+
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ module Reviewable
2
+ class Review < ActiveRecord::Base
3
+ belongs_to :reviewable_object, polymorphic: true
4
+ belongs_to :reviewer, polymorphic: true
5
+
6
+ validates :reviewer_id, uniqueness: {scope: [:reviewable_object_type, :reviewable_object_id, :reviewer_type]}
7
+
8
+ scope :submitted, -> {where.not(submitted_at: nil)}
9
+ scope :unsubmitted, -> {where(submitted_at: nil)}
10
+
11
+ after_initialize :build_default_result
12
+
13
+ def sanitized_results
14
+ enabled_ids = Question.enabled.pluck(:id).map(&:to_s)
15
+ results.slice(*enabled_ids)
16
+ end
17
+
18
+ private
19
+
20
+ def build_default_result
21
+ self.results ||= Question.enabled.pluck(:id).inject({}) {|h, k| h[k] = ''; h }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Reviewable</title>
5
+ <%= stylesheet_link_tag "reviewable/application", media: "all" %>
6
+ <%= javascript_include_tag "reviewable/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,28 @@
1
+ <div class='row'>
2
+ <div class='col-sm-6'>
3
+ <%= simple_form_for @question do |f| %>
4
+ <%= f.input :question_text %>
5
+ <%= f.input :slug %>
6
+ <%= f.input :question_type, collection: Reviewable::Question::TYPES %>
7
+ <div class='hidden_field select'>
8
+ <%= f.input :answer_options_string, hint: 'pipe separated. e.g. good|bad|ugly' %>
9
+ </div>
10
+ <div class='hidden_field integer'>
11
+ <%= f.input :answer_min %>
12
+ <%= f.input :answer_max %>
13
+ </div>
14
+ <%= f.input :enabled %>
15
+ <%= f.button :submit, class: 'btn btn-primary' %>
16
+ <% end %>
17
+ </div>
18
+ </div>
19
+
20
+ <script>
21
+ $('#question_question_type').on('change', function() {
22
+ $('.hidden_field').hide();
23
+ $('.hidden_field.' + this.value).show();
24
+
25
+ });
26
+
27
+ $('#question_question_type').trigger('change');
28
+ </script>
@@ -0,0 +1,10 @@
1
+ <tr>
2
+ <td><%= question.question_text.truncate(30) %></td>
3
+ <td><%= question.question_type %></td>
4
+ <td><%= question.enabled %></td>
5
+ <td><%= question.updated_at %></td>
6
+ <td>
7
+ <%= link_to 'Edit', edit_question_path(question), class: 'btn btn-warning btn-xs' %>
8
+ <%= link_to 'Destroy', question, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-xs' %>
9
+ </td>
10
+ </tr>
@@ -0,0 +1,10 @@
1
+ json.id question.id
2
+ json.question_text question.question_text
3
+ json.question_type question.question_type
4
+ json.slug question.slug
5
+ json.answer_options question.answer_options
6
+ json.answer_min question.answer_min
7
+ json.answer_max question.answer_max
8
+ json.enabled question.enabled
9
+ json.updated_at question.updated_at
10
+ json.created_at question.created_at
@@ -0,0 +1,3 @@
1
+ <h2>Edit Question</h2>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,21 @@
1
+ <h2>Questions</h2>
2
+
3
+ <table class='table table-striped'>
4
+ <thead>
5
+ <tr>
6
+ <th>Question text</th>
7
+ <th>Question type</th>
8
+ <th>Enabled</th>
9
+ <th>Updated at</th>
10
+ <th></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <%= render @questions %>
16
+ </tbody>
17
+ </table>
18
+
19
+ <br>
20
+
21
+ <%= link_to 'New Question', new_question_path, class: 'btn btn-primary' %>
@@ -0,0 +1,5 @@
1
+ json.questions do
2
+ json.array! @questions do |question|
3
+ json.partial! 'reviewable/questions/question', question: question
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ <h2>New Question</h2>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,3 @@
1
+ Reviewable::Engine.routes.draw do
2
+ resources :questions
3
+ end
@@ -0,0 +1,7 @@
1
+ class EnableUuidOsspExtension < ActiveRecord::Migration
2
+ def change
3
+ def change
4
+ enable_extension 'uuid-ossp'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ class CreateReviewableReviews < ActiveRecord::Migration
2
+ def change
3
+ enable_extension 'uuid-ossp'
4
+
5
+ create_table :reviewable_reviews do |t|
6
+ t.references :reviewable_object, :polymorphic => true
7
+ t.references :reviewer, :polymorphic => true
8
+ t.uuid :uuid, default: 'uuid_generate_v4()'
9
+ t.json :results
10
+ t.datetime :submitted_at
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class CreateReviewableQuestions < ActiveRecord::Migration
2
+ def change
3
+ create_table :reviewable_questions do |t|
4
+ t.string :question_text
5
+ t.string :question_type
6
+ t.string :slug
7
+ t.string :answer_options_string
8
+ t.integer :answer_min
9
+ t.integer :answer_max
10
+ t.boolean :enabled
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ require "reviewable/engine"
2
+
3
+ module Reviewable
4
+ end