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,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Concerns::Verifiable do
|
5
|
+
let!(:user) { create :user }
|
6
|
+
let!(:article) { create :article }
|
7
|
+
let!(:task) { create :task }
|
8
|
+
let!(:verification) { create :verification, task: task, verifiable: article }
|
9
|
+
let!(:confirmation) { create :verification_confirmation, author: user, verification: verification }
|
10
|
+
|
11
|
+
it 'has a verification' do
|
12
|
+
expect(article.verification).to eq verification
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has a task' do
|
16
|
+
expect(article.task).to eq task
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has many confirmations' do
|
20
|
+
expect(article.confirmations).to eq [confirmation]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Task do
|
5
|
+
describe "#completed_by" do
|
6
|
+
let!(:user) { create :user }
|
7
|
+
let!(:task) {create(:text_task)}
|
8
|
+
let!(:subject) do
|
9
|
+
create(
|
10
|
+
:tasks_taskables_text_response, author: user,
|
11
|
+
request: task.taskable
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returs completed tasks" do
|
16
|
+
expect(Tasks::Task.completed_by(user)).to eq([task])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Image::Response do
|
5
|
+
let(:user) { create :user }
|
6
|
+
let(:image) {fixture_file_upload('doge.jpg', 'image/jpeg')}
|
7
|
+
|
8
|
+
it_behaves_like "trackable submission" do
|
9
|
+
let!(:task) {create(:image_task)}
|
10
|
+
let!(:subject) do
|
11
|
+
create(
|
12
|
+
:tasks_taskables_image_response, author: user,
|
13
|
+
image: image, request: task.taskable
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Question::Answer do
|
5
|
+
let(:user) { create :user }
|
6
|
+
|
7
|
+
describe '#question' do
|
8
|
+
let(:question) { create :question_with_options }
|
9
|
+
let(:answer) { build :question_answer, author: user, options: [question.options.first] }
|
10
|
+
|
11
|
+
it 'should derive the question it is an answer to' do
|
12
|
+
expect(answer.question).to eq question
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'validations' do
|
17
|
+
describe '#can_only_answer_each_question_once' do
|
18
|
+
let!(:question) { create :question_with_options }
|
19
|
+
let!(:answer) { create :question_answer, author: user, options: [question.options.first] }
|
20
|
+
let!(:duplicate_answer) { build :question_answer, author: user, options: [question.options.first] }
|
21
|
+
|
22
|
+
it 'prohibits an author from answering the same question more than once' do
|
23
|
+
expect(duplicate_answer).not_to be_valid
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have errors' do
|
27
|
+
expect(duplicate_answer.errors_on(:base)).to eq [I18n.t('tasks.taskables.questions.answers.already_answered')]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#can_only_vote_once_for_single_choice_questions' do
|
32
|
+
let!(:question) { create :question_with_options, multiple: false }
|
33
|
+
let!(:answer) { build :question_answer, author: user, options: [question.options.first, question.options.second] }
|
34
|
+
|
35
|
+
it 'prohibits an author from answering the same question more than once' do
|
36
|
+
expect(answer).not_to be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should have errors' do
|
40
|
+
expect(answer.errors_on(:base)).to eq [I18n.t('tasks.taskables.questions.answers.can_only_vote_once')]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#correct?' do
|
46
|
+
let(:question) { create :question_with_options, multiple: true, options_count: 3 }
|
47
|
+
let(:first_option) { question.options[0] }
|
48
|
+
let(:second_option) { question.options[1] }
|
49
|
+
|
50
|
+
context 'multiple correct options' do
|
51
|
+
it 'should return true if all votes are correct' do
|
52
|
+
first_option.update_attributes!(correct: true)
|
53
|
+
second_option.update_attributes!(correct: true)
|
54
|
+
answer = create :question_answer, options: [first_option, second_option]
|
55
|
+
expect(answer).to be_correct
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return false unless all votes are true' do
|
59
|
+
first_option.update_attributes!(correct: true)
|
60
|
+
answer = create :question_answer, options: [first_option, second_option]
|
61
|
+
expect(answer).not_to be_correct
|
62
|
+
end
|
63
|
+
end
|
64
|
+
context 'one correct option' do
|
65
|
+
it 'should return true if all votes are correct' do
|
66
|
+
first_option.update_attributes!(correct: true)
|
67
|
+
answer = create :question_answer, options: [first_option]
|
68
|
+
expect(answer).to be_correct
|
69
|
+
end
|
70
|
+
it 'should return false unless all votes are true' do
|
71
|
+
first_option.update_attributes!(correct: true)
|
72
|
+
answer = create :question_answer, options: [first_option, second_option]
|
73
|
+
expect(answer).not_to be_correct
|
74
|
+
end
|
75
|
+
end
|
76
|
+
context 'no correct options' do
|
77
|
+
it 'should always return false' do
|
78
|
+
answer = create :question_answer, options: [first_option]
|
79
|
+
expect(answer).not_to be_correct
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it_behaves_like "trackable submission" do
|
85
|
+
let!(:task) {create(:question_task)}
|
86
|
+
let!(:subject) do
|
87
|
+
create :question_answer, author: user, options: [task.taskable.options.first]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Question do
|
5
|
+
let!(:user) { create :user }
|
6
|
+
let!(:question) { create :question_with_options }
|
7
|
+
let!(:answer) { create :question_answer, author: user, options: [question.options.first, question.options.second] }
|
8
|
+
|
9
|
+
describe '#answers' do
|
10
|
+
let!(:other_question) { create :question_with_options }
|
11
|
+
let!(:other_answer) { create :question_answer, author: user, options: [other_question.options.first, other_question.options.second] }
|
12
|
+
|
13
|
+
it 'should derive its answers' do
|
14
|
+
expect(question.answers.count).to eq 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Taskable::Submission do
|
5
|
+
class Answer
|
6
|
+
|
7
|
+
# This is probably a bad idea, but otherwise Ruby will complain that there's
|
8
|
+
# no 'has_one' method on my stub and I don't really care about that.
|
9
|
+
class << self
|
10
|
+
def method_missing *args; end
|
11
|
+
end
|
12
|
+
|
13
|
+
include Taskables::Taskable::Submission
|
14
|
+
|
15
|
+
def question
|
16
|
+
'foo'
|
17
|
+
end
|
18
|
+
|
19
|
+
request is: :question
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.request' do
|
23
|
+
|
24
|
+
it 'aliases a given relation to request' do
|
25
|
+
expect(Answer.new.request).to eq 'foo'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Taskable do
|
5
|
+
class Question
|
6
|
+
|
7
|
+
# This is probably a bad idea, but otherwise Ruby will complain that there's
|
8
|
+
# no 'has_one' method on my stub and I don't really care about that.
|
9
|
+
class << self
|
10
|
+
def method_missing *args; end
|
11
|
+
end
|
12
|
+
|
13
|
+
include Taskables::Taskable
|
14
|
+
|
15
|
+
def answers
|
16
|
+
['foo', 'bar', 'baz']
|
17
|
+
end
|
18
|
+
|
19
|
+
responses are: :answers
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.submissions' do
|
23
|
+
|
24
|
+
it 'aliases a given relation to responses' do
|
25
|
+
expect(Question.new.responses).to eq ['foo', 'bar', 'baz']
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#completed_by?' do
|
31
|
+
let(:taskable) { create :verification }
|
32
|
+
let(:user) { create :user }
|
33
|
+
|
34
|
+
context 'with an incomplete task' do
|
35
|
+
it 'determines that the author has not completed it' do
|
36
|
+
expect(taskable).not_to be_completed_by user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with a completed task' do
|
41
|
+
before { create :verification_confirmation, author: user, verification: taskable }
|
42
|
+
|
43
|
+
it 'determines that the author has completed it' do
|
44
|
+
expect(taskable).to be_completed_by user
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Text::Response do
|
5
|
+
let(:user) { create :user }
|
6
|
+
|
7
|
+
it_behaves_like "trackable submission" do
|
8
|
+
let!(:task) {create(:text_task)}
|
9
|
+
let!(:subject) do
|
10
|
+
create(
|
11
|
+
:tasks_taskables_text_response, author: user,
|
12
|
+
request: task.taskable
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Tasks
|
4
|
+
describe Taskables::Verification do
|
5
|
+
describe 'uniqueness validation on verifiable' do
|
6
|
+
let(:article) { create :article }
|
7
|
+
let(:duplicate) { build :verification, verifiable: article }
|
8
|
+
|
9
|
+
before do
|
10
|
+
create :verification, verifiable: article
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'prohibits saving multiple verifications for the same verifiable' do
|
14
|
+
expect(duplicate).not_to be_valid
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'factory_girl_rails'
|
7
|
+
|
8
|
+
Rails.backtrace_cleaner.remove_silencers!
|
9
|
+
|
10
|
+
# Load support files
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
|
+
|
13
|
+
# Load dummy factories
|
14
|
+
Dir["#{File.dirname(__FILE__)}/dummy/spec/factories/**/*.rb"].each { |f| require f }
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.mock_with :rspec
|
18
|
+
config.use_transactional_fixtures = true
|
19
|
+
config.infer_base_class_for_anonymous_controllers = false
|
20
|
+
config.order = 'random'
|
21
|
+
|
22
|
+
config.include FactoryGirl::Syntax::Methods
|
23
|
+
config.include ActionDispatch::TestProcess
|
24
|
+
|
25
|
+
config.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
|
26
|
+
end
|
27
|
+
|
28
|
+
CarrierWave.configure do |config|
|
29
|
+
config.storage = :file
|
30
|
+
config.enable_processing = false
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_examples 'redirectable' do
|
2
|
+
let(:explicit_redirect) { 'http://explicit_redirect.org' }
|
3
|
+
let(:implicit_redirect) { 'http://implicit_redirect.org' }
|
4
|
+
|
5
|
+
before { request.env['HTTP_REFERER'] = implicit_redirect }
|
6
|
+
|
7
|
+
context 'with redirect_to set' do
|
8
|
+
before do
|
9
|
+
params[:redirect_to] = explicit_redirect
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'redirects to the given url' do
|
13
|
+
send(verb, action, params)
|
14
|
+
expect(response).to redirect_to explicit_redirect
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'without redirect_to set' do
|
19
|
+
context 'without after_completion_path defined' do
|
20
|
+
it 'redirects back' do
|
21
|
+
send(verb, action, params)
|
22
|
+
expect(response).to redirect_to implicit_redirect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with after_completion_path defined' do
|
27
|
+
let(:after_completion_path ) { 'http://after_completion_path.org' }
|
28
|
+
|
29
|
+
before { expect(subject).to receive(:after_completion_path_for).and_return after_completion_path }
|
30
|
+
|
31
|
+
it 'redirects to the configured url' do
|
32
|
+
send(verb, action, params)
|
33
|
+
expect(response).to redirect_to after_completion_path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples "trackable submission" do
|
4
|
+
describe "callbacks for response" do
|
5
|
+
it "create response on trackable create" do
|
6
|
+
expect(Tasks::Taskables::Taskable::Response.count).to eq(1)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "destroy response on trackable destroy" do
|
10
|
+
subject.destroy
|
11
|
+
expect(Tasks::Taskables::Taskable::Response.count).to eq(0)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|