tasuku 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/README.md +82 -0
- data/Rakefile +28 -0
- data/app/assets/javascripts/tasks/application.js +13 -0
- data/app/assets/stylesheets/tasks/application.css +15 -0
- data/app/controllers/tasks/application_controller.rb +13 -0
- data/app/controllers/tasks/taskables/image/responses_controller.rb +32 -0
- data/app/controllers/tasks/taskables/questions/answers_controller.rb +37 -0
- data/app/controllers/tasks/taskables/text/responses_controller.rb +32 -0
- data/app/controllers/tasks/taskables/url/responses_controller.rb +32 -0
- data/app/controllers/tasks/taskables/verifications/confirmations_controller.rb +28 -0
- data/app/controllers/tasks/tasks_controller.rb +7 -0
- data/app/helpers/tasks/application_helper.rb +7 -0
- data/app/helpers/tasks/taskables/verifications_helper.rb +18 -0
- data/app/models/tasks/task.rb +5 -0
- data/app/models/tasks/taskables.rb +7 -0
- data/app/models/tasks/taskables/image.rb +7 -0
- data/app/models/tasks/taskables/image/request.rb +7 -0
- data/app/models/tasks/taskables/image/response.rb +17 -0
- data/app/models/tasks/taskables/question.rb +7 -0
- data/app/models/tasks/taskables/question/answer.rb +39 -0
- data/app/models/tasks/taskables/question/option.rb +7 -0
- data/app/models/tasks/taskables/question/vote.rb +6 -0
- data/app/models/tasks/taskables/taskable.rb +31 -0
- data/app/models/tasks/taskables/taskable/response.rb +9 -0
- data/app/models/tasks/taskables/taskable/submission.rb +39 -0
- data/app/models/tasks/taskables/text.rb +7 -0
- data/app/models/tasks/taskables/text/request.rb +7 -0
- data/app/models/tasks/taskables/text/response.rb +15 -0
- data/app/models/tasks/taskables/url.rb +7 -0
- data/app/models/tasks/taskables/url/request.rb +5 -0
- data/app/models/tasks/taskables/url/response.rb +18 -0
- data/app/models/tasks/taskables/verification.rb +7 -0
- data/app/models/tasks/taskables/verification/confirmation.rb +12 -0
- data/app/uploaders/tasks/image_uploader.rb +58 -0
- data/app/views/tasks/taskables/image/requests/_request.html.erb +19 -0
- data/app/views/tasks/taskables/image/responses/_form.html.erb +8 -0
- data/app/views/tasks/taskables/image/responses/create.html.erb +2 -0
- data/app/views/tasks/taskables/questions/_question.html.erb +27 -0
- data/app/views/tasks/taskables/questions/answers/_form.html.erb +16 -0
- data/app/views/tasks/taskables/questions/answers/_statistics.html.erb +26 -0
- data/app/views/tasks/taskables/text/requests/_request.html.erb +19 -0
- data/app/views/tasks/taskables/text/responses/_form.html.erb +5 -0
- data/app/views/tasks/taskables/text/responses/create.html.erb +2 -0
- data/app/views/tasks/taskables/url/requests/_request.html.erb +19 -0
- data/app/views/tasks/taskables/url/responses/_form.html.erb +5 -0
- data/app/views/tasks/taskables/url/responses/create.html.erb +2 -0
- data/app/views/tasks/taskables/verifications/_verification.html.erb +1 -0
- data/app/views/tasks/taskables/verifications/confirmations/_form.html.erb +3 -0
- data/app/views/tasks/tasks/_task.html.erb +3 -0
- data/app/views/tasks/tasks/show.html.erb +1 -0
- data/config/locales/en.yml +24 -0
- data/config/locales/nb.yml +122 -0
- data/config/routes.rb +35 -0
- data/db/migrate/20140315151838_create_tasks_tasks.rb +9 -0
- data/db/migrate/20140315152116_create_tasks_taskables_verifications.rb +11 -0
- data/db/migrate/20140315153512_create_tasks_taskables_verification_confirmations.rb +13 -0
- data/db/migrate/20140316203422_create_tasks_taskables_questions.rb +9 -0
- data/db/migrate/20140316203812_create_tasks_taskables_question_options.rb +10 -0
- data/db/migrate/20140316204119_create_tasks_taskables_question_answers.rb +12 -0
- data/db/migrate/20140316221703_remove_unique_constraint_on_task_taskable_question_answer_index.rb +6 -0
- data/db/migrate/20140320123047_remove_unique_constraint_on_confirmation_author.rb +6 -0
- data/db/migrate/20140402132837_create_tasks_taskables_image_requests.rb +9 -0
- data/db/migrate/20140402135306_create_tasks_taskables_image_responses.rb +13 -0
- data/db/migrate/20140403090537_remove_unique_constraint_on_image_response_author.rb +6 -0
- data/db/migrate/20140404113158_add_description_to_taskables_questions.rb +5 -0
- data/db/migrate/20140404130151_add_description_to_tasks_taskables_image_requests.rb +5 -0
- data/db/migrate/20140512072931_create_tasks_taskables_url_requests.rb +10 -0
- data/db/migrate/20140512074135_create_tasks_taskables_url_responses.rb +13 -0
- data/db/migrate/20140512120632_create_tasks_taskables_question_votes.rb +10 -0
- data/db/migrate/20140512121254_add_multiple_to_question.rb +5 -0
- data/db/migrate/20140512131526_remove_option_id_from_questions.rb +21 -0
- data/db/migrate/20140514082129_create_tasks_taskables_text_requests.rb +10 -0
- data/db/migrate/20140514082143_create_tasks_taskables_text_responses.rb +13 -0
- data/db/migrate/20140520122938_add_correct_to_tasks_taskables_question_option.rb +5 -0
- data/db/migrate/20140521134515_add_show_statistics_to_tasks_taskables_question.rb +5 -0
- data/db/migrate/20140523091152_add_images.rb +8 -0
- data/db/migrate/20140604075046_add_obligatory_to_tasks_task.rb +5 -0
- data/db/migrate/20140605095241_create_tasks_taskables_taskable_responses.rb +10 -0
- data/db/migrate/20140605124021_add_task_to_response.rb +6 -0
- data/db/migrate/20140606072225_migrate_existing_date.rb +15 -0
- data/lib/generators/tasks/install/USAGE +8 -0
- data/lib/generators/tasks/install/install_generator.rb +23 -0
- data/lib/generators/tasks/install/templates/tasks.rb +3 -0
- data/lib/generators/tasks/views/USAGE +5 -0
- data/lib/generators/tasks/views/views_generator.rb +9 -0
- data/lib/tasks.rb +20 -0
- data/lib/tasks/concerns.rb +7 -0
- data/lib/tasks/concerns/controllers.rb +5 -0
- data/lib/tasks/concerns/controllers/tasks_controller.rb +18 -0
- data/lib/tasks/concerns/illustratable.rb +9 -0
- data/lib/tasks/concerns/models.rb +4 -0
- data/lib/tasks/concerns/models/task.rb +25 -0
- data/lib/tasks/concerns/models/taskables.rb +7 -0
- data/lib/tasks/concerns/models/taskables/image.rb +3 -0
- data/lib/tasks/concerns/models/taskables/image/request.rb +18 -0
- data/lib/tasks/concerns/models/taskables/question.rb +31 -0
- data/lib/tasks/concerns/models/taskables/text.rb +3 -0
- data/lib/tasks/concerns/models/taskables/text/request.rb +18 -0
- data/lib/tasks/concerns/models/taskables/url.rb +3 -0
- data/lib/tasks/concerns/models/taskables/url/request.rb +18 -0
- data/lib/tasks/concerns/models/taskables/verification.rb +20 -0
- data/lib/tasks/concerns/redirectable.rb +11 -0
- data/lib/tasks/concerns/verifiable.rb +9 -0
- data/lib/tasks/engine.rb +22 -0
- data/lib/tasks/seeds.rb +13 -0
- data/lib/tasks/tasks_tasks.rake +4 -0
- data/lib/tasks/version.rb +3 -0
- data/lib/tasuku.rb +1 -0
- data/spec/controllers/tasks/taskables/image/responses_controller_spec.rb +37 -0
- data/spec/controllers/tasks/taskables/questions/answers_controller_spec.rb +39 -0
- data/spec/controllers/tasks/taskables/text/responses_controller_spec.rb +37 -0
- data/spec/controllers/tasks/taskables/verifications/confirmations_controller_spec.rb +38 -0
- data/spec/controllers/tasks/tasks_controller_spec.rb +17 -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 +7 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/models/article.rb +3 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +17 -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 +30 -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 +83 -0
- data/spec/dummy/config/environments/test.rb +39 -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 +5 -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/20140315162017_create_users.rb +8 -0
- data/spec/dummy/db/migrate/20140315185502_create_articles.rb +8 -0
- data/spec/dummy/db/schema.rb +166 -0
- data/spec/dummy/db/seeds.rb +3 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +90 -0
- data/spec/dummy/log/test.log +2568 -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/public/uploads/tasks/taskables/image/request/image/1/doge.jpg +0 -0
- data/spec/dummy/public/uploads/tasks/taskables/image/response/image/1/doge.jpg +0 -0
- data/spec/dummy/public/uploads/tasks/taskables/question/image/1/doge.jpg +0 -0
- data/spec/dummy/public/uploads/tasks/taskables/text/request/image/1/doge.jpg +0 -0
- data/spec/dummy/public/uploads/tasks/taskables/url/request/image/1/doge.jpg +0 -0
- data/spec/dummy/spec/factories/articles.rb +6 -0
- data/spec/dummy/spec/factories/users.rb +6 -0
- data/spec/dummy/spec/models/article_spec.rb +4 -0
- data/spec/dummy/spec/models/user_spec.rb +4 -0
- data/spec/factories/tasks_taskables_image_requests.rb +7 -0
- data/spec/factories/tasks_taskables_image_responses.rb +8 -0
- data/spec/factories/tasks_taskables_question_answers.rb +17 -0
- data/spec/factories/tasks_taskables_question_options.rb +10 -0
- data/spec/factories/tasks_taskables_question_votes.rb +8 -0
- data/spec/factories/tasks_taskables_questions.rb +19 -0
- data/spec/factories/tasks_taskables_taskable_responses.rb +8 -0
- data/spec/factories/tasks_taskables_text_requests.rb +5 -0
- data/spec/factories/tasks_taskables_text_responses.rb +6 -0
- data/spec/factories/tasks_taskables_url_requests.rb +8 -0
- data/spec/factories/tasks_taskables_url_responses.rb +9 -0
- data/spec/factories/tasks_taskables_verification_confirmations.rb +8 -0
- data/spec/factories/tasks_taskables_verifications.rb +7 -0
- data/spec/factories/tasks_tasks.rb +14 -0
- data/spec/fixtures/doge.jpg +0 -0
- data/spec/helpers/tasks/taskables/verifications_helper_spec.rb +20 -0
- data/spec/lib/generators/views_generators_spec.rb +22 -0
- data/spec/lib/tasks/concerns/verifiable_spec.rb +23 -0
- data/spec/models/tasks/task_spec.rb +20 -0
- data/spec/models/tasks/taskables/image/request_spec.rb +6 -0
- data/spec/models/tasks/taskables/image/response_spec.rb +18 -0
- data/spec/models/tasks/taskables/question/answer_spec.rb +91 -0
- data/spec/models/tasks/taskables/question/option_spec.rb +6 -0
- data/spec/models/tasks/taskables/question/vote_spec.rb +6 -0
- data/spec/models/tasks/taskables/question_spec.rb +18 -0
- data/spec/models/tasks/taskables/taskable/response_spec.rb +7 -0
- data/spec/models/tasks/taskables/taskable/submission_spec.rb +30 -0
- data/spec/models/tasks/taskables/taskable_spec.rb +49 -0
- data/spec/models/tasks/taskables/text/request_spec.rb +6 -0
- data/spec/models/tasks/taskables/text/response_spec.rb +17 -0
- data/spec/models/tasks/taskables/url/request_spec.rb +6 -0
- data/spec/models/tasks/taskables/url/response_spec.rb +6 -0
- data/spec/models/tasks/taskables/verification/confirmation_spec.rb +6 -0
- data/spec/models/tasks/taskables/verification_spec.rb +18 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/fixture.rb +3 -0
- data/spec/support/shared_examples_for_redirectable.rb +37 -0
- data/spec/support/trackable_submission_spec.rb +14 -0
- data/spec/views/tasks/taskables/image/requests/_request.html.erb_spec.rb +35 -0
- data/spec/views/tasks/taskables/image/responses/create.html.erb_spec.rb +4 -0
- data/spec/views/tasks/taskables/questions/_question.html.erb_spec.rb +35 -0
- data/spec/views/tasks/taskables/questions/answers/_form.html.erb_spec.rb +18 -0
- data/spec/views/tasks/taskables/text/requests/_request.html.erb_spec.rb +35 -0
- data/spec/views/tasks/taskables/url/requests/_request.html.erb_spec.rb +35 -0
- data/spec/views/tasks/taskables/verifications/confirmations/_form.html.erb_spec.rb +17 -0
- data/spec/views/tasks/tasks/show.html.erb_spec.rb +4 -0
- metadata +550 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateTasksTaskablesTaskableResponses < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :tasks_taskables_taskable_responses do |t|
|
4
|
+
t.references :submittable, polymorphic: true
|
5
|
+
t.references :author, polymorphic: true
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MigrateExistingDate < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
%w(Image::Response Question::Answer Text::Response URL::Response).each do |class_name|
|
4
|
+
"Tasks::Taskables::#{class_name}".constantize.send(:all) do |model|
|
5
|
+
if model.request.task.present?
|
6
|
+
Tasks::Taskables::Taskable::Response.create do |response|
|
7
|
+
response.author = model.author
|
8
|
+
response.submittable = model
|
9
|
+
response.task = model.request.task
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Tasks::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
desc 'Install the default configurations for Tasks'
|
5
|
+
|
6
|
+
def copy_initializer
|
7
|
+
template 'tasks.rb', 'config/initializers/tasks.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_route
|
11
|
+
route "mount Tasks::Engine, at: '/tasks'"
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_helpers
|
15
|
+
inject_into_file 'app/controllers/application_controller.rb',
|
16
|
+
"\n helper Tasks::Engine.helpers",
|
17
|
+
after: 'protect_from_forgery with: :exception'
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_migrations
|
21
|
+
rake 'tasks:install:migrations'
|
22
|
+
end
|
23
|
+
end
|
data/lib/tasks.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "tasks/engine"
|
2
|
+
require "tasks/concerns"
|
3
|
+
|
4
|
+
require "configatron/core"
|
5
|
+
require "carrierwave"
|
6
|
+
require "embeddable"
|
7
|
+
|
8
|
+
module Tasks
|
9
|
+
class << self
|
10
|
+
def configure
|
11
|
+
yield config
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
@config ||= Configatron::Store.new author: :current_user
|
16
|
+
|
17
|
+
@config
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tasks
|
2
|
+
module Concerns::Controllers::TasksController
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :set_task
|
7
|
+
|
8
|
+
def show
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def set_task
|
14
|
+
@task = Task.find params[:id]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Tasks::Concerns::Models::Task
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
belongs_to :taskable, polymorphic: true
|
6
|
+
has_many :responses, class_name: '::Tasks::Taskables::Taskable::Response'
|
7
|
+
|
8
|
+
scope :completed_by, ->(author) do
|
9
|
+
joins(:responses).where(
|
10
|
+
"tasks_taskables_taskable_responses.author_id = ? and
|
11
|
+
tasks_taskables_taskable_responses.author_type = ?",
|
12
|
+
author.id, author.class.name
|
13
|
+
).uniq
|
14
|
+
end
|
15
|
+
scope :incomplete_by, ->(author) { all.reject { |task| task.completed_by? author }}
|
16
|
+
|
17
|
+
validates :taskable, presence: true
|
18
|
+
|
19
|
+
delegate :completed_by?, :submissions, to: :taskable
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
taskable.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module Tasks::Concerns::Models::Taskables
|
2
|
+
require "tasks/concerns/models/taskables/image"
|
3
|
+
require "tasks/concerns/models/taskables/question"
|
4
|
+
require "tasks/concerns/models/taskables/text"
|
5
|
+
require "tasks/concerns/models/taskables/url"
|
6
|
+
require "tasks/concerns/models/taskables/verification"
|
7
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tasks
|
2
|
+
module Concerns::Models::Taskables::Image::Request
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ::Tasks::Taskables::Taskable
|
7
|
+
include ::Tasks::Concerns::Illustratable
|
8
|
+
|
9
|
+
has_many :responses
|
10
|
+
|
11
|
+
responses are: :responses
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
text
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Tasks
|
2
|
+
module Concerns::Models::Taskables::Question
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ::Tasks::Taskables::Taskable
|
7
|
+
include ::Tasks::Concerns::Illustratable
|
8
|
+
|
9
|
+
has_many :options
|
10
|
+
has_many :votes, through: :options
|
11
|
+
|
12
|
+
accepts_nested_attributes_for :options, allow_destroy: true
|
13
|
+
|
14
|
+
def answers
|
15
|
+
Taskables::Question::Answer.joins(:votes).where(
|
16
|
+
Taskables::Question::Vote.table_name => { option_id: options.pluck(:id) }
|
17
|
+
).uniq
|
18
|
+
end
|
19
|
+
|
20
|
+
def single?
|
21
|
+
!multiple?
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
text
|
26
|
+
end
|
27
|
+
|
28
|
+
responses are: :answers
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tasks
|
2
|
+
module Concerns::Models::Taskables::Text::Request
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ::Tasks::Taskables::Taskable
|
7
|
+
include ::Tasks::Concerns::Illustratable
|
8
|
+
|
9
|
+
has_many :responses, dependent: :destroy
|
10
|
+
|
11
|
+
responses are: :responses
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
text
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tasks
|
2
|
+
module Concerns::Models::Taskables::URL::Request
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ::Tasks::Taskables::Taskable
|
7
|
+
include ::Tasks::Concerns::Illustratable
|
8
|
+
|
9
|
+
has_many :responses, dependent: :destroy
|
10
|
+
|
11
|
+
responses are: :responses
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
text
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tasks
|
2
|
+
module Concerns::Models::Taskables::Verification
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ::Tasks::Taskables::Taskable
|
7
|
+
|
8
|
+
belongs_to :verifiable, polymorphic: true
|
9
|
+
has_many :confirmations, dependent: :destroy
|
10
|
+
|
11
|
+
validates :verifiable_id, allow_blank: true, uniqueness: { scope: [:verifiable_type] }
|
12
|
+
|
13
|
+
responses are: :confirmations
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
verifiable.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Tasks::Concerns::Verifiable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
has_one :verification, as: :verifiable, class_name: '::Tasks::Taskables::Verification', dependent: :destroy
|
6
|
+
has_one :task, through: :verification, class_name: '::Tasks::Task'
|
7
|
+
has_many :confirmations, through: :verification, class_name: '::Tasks::Taskables::Verification::Confirmation'
|
8
|
+
end
|
9
|
+
end
|
data/lib/tasks/engine.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Tasks
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Tasks
|
4
|
+
|
5
|
+
initializer 'tasks.factories', after: 'factory_girl.set_factory_paths' do
|
6
|
+
FactoryGirl.definition_file_paths << File.expand_path('../../../spec/factories', __FILE__) if defined?(FactoryGirl)
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer 'tasks.inflections' do
|
10
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
11
|
+
inflect.acronym "URL"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config.generators do |g|
|
16
|
+
g.test_framework :rspec, fixture: false
|
17
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
18
|
+
g.assets false
|
19
|
+
g.helper false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/tasks/seeds.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
image_request = Tasks::Taskables::Image::Request.create! text: "Upload a picture"
|
2
|
+
task = Tasks::Task.create! taskable: image_request
|
3
|
+
|
4
|
+
url_request = Tasks::Taskables::URL::Request.create! text: "Specify a URL"
|
5
|
+
task = Tasks::Task.create! taskable: url_request
|
6
|
+
|
7
|
+
text_request = Tasks::Taskables::Text::Request.create! text: "Write something"
|
8
|
+
task = Tasks::Task.create! taskable: text_request
|
9
|
+
|
10
|
+
question = Tasks::Taskables::Question.create! text: "Choose something"
|
11
|
+
option = Tasks::Taskables::Question::Option.create! question: question, text: "One option"
|
12
|
+
option = Tasks::Taskables::Question::Option.create! question: question, text: "Another option"
|
13
|
+
task = Tasks::Task.create! taskable: question
|
data/lib/tasuku.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "tasks"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Image::ResponsesController do
|
5
|
+
routes { Tasks::Engine.routes }
|
6
|
+
|
7
|
+
describe "POST 'create'" do
|
8
|
+
it 'routes' do
|
9
|
+
expect(post: '/image/requests/1/responses').to route_to(
|
10
|
+
action: 'create',
|
11
|
+
controller: 'tasks/taskables/image/responses',
|
12
|
+
request_id: '1'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a response' do
|
17
|
+
let(:user) { create :user }
|
18
|
+
let(:image_request) { create :image_request }
|
19
|
+
let(:params) { { request_id: image_request.id, taskables_image_response: { image: fixture_file_upload('doge.jpg', 'image/jpg') } } }
|
20
|
+
|
21
|
+
before { request.env['HTTP_REFERER'] = 'http://example.org' }
|
22
|
+
before { expect(subject).to receive(:current_user).and_return(user) }
|
23
|
+
|
24
|
+
it_behaves_like 'redirectable' do
|
25
|
+
let(:action) { :create }
|
26
|
+
let(:verb) { :post }
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'creates a new response' do
|
30
|
+
post :create, params
|
31
|
+
|
32
|
+
expect(image_request.responses.count).to eq 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|