Skip to content

Commit

Permalink
Merge f79c0c8 into be583c8
Browse files Browse the repository at this point in the history
  • Loading branch information
simonreed committed Sep 26, 2019
2 parents be583c8 + f79c0c8 commit 1097644
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/linkable.rb
Expand Up @@ -6,7 +6,9 @@ module Model
has_one :topic, through: :link

def get_ancestral_topic
if self.respond_to? :find_closest_ancestor_topic
if self.respond_to? :resolved_topic
self.resolved_topic
elsif self.respond_to? :find_closest_ancestor_topic
self.find_closest_ancestor_topic
else
nil
Expand Down
13 changes: 13 additions & 0 deletions test/controllers/cc_questions_controller_test.rb
Expand Up @@ -78,4 +78,17 @@ class CcQuestionsControllerTest < ActionController::TestCase
parsed_response = response.body.split("\n").map{|line| line.split("\t")}
assert_equal parsed_response.first, [cc_question.control_construct_scheme, cc_question.label, cc_question.fully_resolved_topic_code]
end

test "should show inherited topic in tq.txt if no topic is explicitly set for a cc_question" do
instrument = FactoryBot.create(:instrument)
cc_question = FactoryBot.create(:cc_question, instrument: instrument, label: 'qc_abc_123', topic: nil)
topic = FactoryBot.create(:topic)
variable = FactoryBot.create(:variable)
variable.topic = topic
cc_question.variables << variable
get :tq, format: :txt, params: { instrument_id: instrument.id }
assert_response :success
parsed_response = response.body.split("\n").map{|line| line.split("\t")}
assert_equal parsed_response.first, [cc_question.control_construct_scheme, cc_question.label, topic.code]
end
end

0 comments on commit 1097644

Please sign in to comment.