Commit 49fc73d73ef6815bc02ab44ef6717da8bf574b06
1 parent
a36f5919
Exists in
master
and in
28 other branches
Adds named_scope for easy retrieval of tasks requested by profile
Showing
2 changed files
with
16 additions
and
1 deletions
Show diff stats
plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb
... | ... | @@ -5,6 +5,8 @@ class CustomFormsPlugin::MembershipSurvey < Task |
5 | 5 | |
6 | 6 | include CustomFormsPlugin::Helper |
7 | 7 | |
8 | + named_scope :from, lambda {|profile| {:conditions => {:requestor_id => profile.id}}} | |
9 | + | |
8 | 10 | def perform |
9 | 11 | form = CustomFormsPlugin::Form.find(form_id) |
10 | 12 | answers = build_answers(submission, form) | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb
... | ... | @@ -23,9 +23,22 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
23 | 23 | end |
24 | 24 | |
25 | 25 | submission = CustomFormsPlugin::Submission.last |
26 | - assert_equal submission.answers.count, 1 | |
26 | + assert_equal submission.answers.count, 1 | |
27 | 27 | |
28 | 28 | answer = submission.answers.first |
29 | 29 | assert_equal answer.value, 'Jack' |
30 | 30 | end |
31 | + | |
32 | + should 'have a named_scope that retrieves all tasks requested by profile' do | |
33 | + profile = fast_create(Profile) | |
34 | + person = fast_create(Person) | |
35 | + form = CustomFormsPlugin::Form.create!(:name => 'Simple Form', :profile => profile) | |
36 | + task1 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :target => person, :requestor => profile) | |
37 | + task2 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :target => person, :requestor => fast_create(Profile)) | |
38 | + scope = CustomFormsPlugin::MembershipSurvey.from(profile) | |
39 | + | |
40 | + assert_equal ActiveRecord::NamedScope::Scope, scope.class | |
41 | + assert_includes scope, task1 | |
42 | + assert_not_includes scope, task2 | |
43 | + end | |
31 | 44 | end | ... | ... |