diff --git a/Gemfile b/Gemfile index 2d9b5b9..7ed9ca7 100644 --- a/Gemfile +++ b/Gemfile @@ -72,7 +72,7 @@ gem 'wkhtmltopdf-binary' gem 'thin' gem 'wicked_pdf' -gem 'htmltoword' +gem 'htmltoword', '>= 0.7' gem 'feedjira' gem 'yaml_db', :git => 'https://github.com/vyruss/yaml_db.git' diff --git a/Gemfile.lock b/Gemfile.lock index 53bf3cf..bde99fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,7 +142,7 @@ activesupport (>= 4.1.0) hashdiff (0.3.0) hashie (3.4.6) - htmltoword (0.5.1) + htmltoword (0.7.0) actionpack nokogiri rubyzip (>= 1.0) @@ -282,7 +282,7 @@ railties (>= 4.2.0, < 5.1) rolify (5.1.0) ruby-progressbar (1.8.1) - rubyzip (1.2.0) + rubyzip (1.2.1) safe_yaml (1.0.4) sass (3.4.22) sass-rails (5.0.6) @@ -368,7 +368,7 @@ gettext (>= 3.0.2) gettext_i18n_rails (~> 1.8) gettext_i18n_rails_js (~> 1.2.0) - htmltoword + htmltoword (>= 0.7) i18n-js (>= 3.0.0.rc11) jbuilder jquery-rails diff --git a/test/integration/template_selection_test.rb b/test/integration/template_selection_test.rb index 2567954..eb95dc7 100644 --- a/test/integration/template_selection_test.rb +++ b/test/integration/template_selection_test.rb @@ -5,100 +5,102 @@ setup do scaffold_template - @template.is_default = true - @template.published = true - @template.save! - + @template = Template.default + @researcher = User.last - + scaffold_org_admin(@template.org) - + @funder = Org.find_by(org_type: 2) - @funder_template = Template.create(title: 'Funder template', org: @funder, migrated: false) + @funder_template = @funder.templates.where(published: true).first #Template.create(title: 'Funder template', org: @funder, migrated: false) # Template can't be published on creation so do it afterward @funder_template.published = true @funder_template.save - + @org = @researcher.org @org_template = Template.create(title: 'Org template', org: @org, migrated: false) # Template can't be published on creation so do it afterward @org_template.published = true @org_template.save end - + # ---------------------------------------------------------- test 'plan gets publish versions of templates' do original_id = @template.id template = version_template(@template) - + sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: @template.org.id}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{original_id}\");") assert_equal original_id, Template.live(@template.dmptemplate_id).id - + # Version the template again original_id = template.id template = version_template(template) - + # Make sure the published version is used post plans_path(format: :js), {plan: {org_id: @template.org.id}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{original_id}\");") assert_equal original_id, Template.live(@template.dmptemplate_id).id - + # Update the template and make sure the published version stayed the same sign_in @user put admin_update_template_path(template), {template: {title: "Blah blah blah"}} - + sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: @template.org.id}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{original_id}\");") assert_equal original_id, Template.live(@template.dmptemplate_id).id end - + # ---------------------------------------------------------- test 'plan gets generic template when no funder or org' do - @template.is_default = true - @template.save! - + temp = Template.find_by(published: true, is_default: true) + if temp.blank? + @template.is_default = true + @template.save! + temp = @template + end + sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: nil}} assert_response :success - assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@template.id}\");"), @response.body + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{temp.id}\");"), @response.body end - + # ---------------------------------------------------------- test 'plan gets org template when no funder' do sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: nil}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@org_template.id}\");"), @response.body end - + # ---------------------------------------------------------- test 'plan gets funder template when no org' do sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: nil, funder_id: @funder.id}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@funder_template.id}\");"), @response.body end - + # ---------------------------------------------------------- test 'plan gets funder template when org has no customization' do sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: @funder.id}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@funder_template.id}\");"), @response.body end - + # ---------------------------------------------------------- test 'plan gets customized version of funder template' do customization = Template.create(title: 'Customization', org: @org) @@ -106,9 +108,9 @@ customization.published = true customization.customization_of = @funder_template.dmptemplate_id customization.save - + sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: @funder.id}} assert_response :success assert @response.body.include?("$(\"#plan_template_id\").val(\"#{customization.id}\");"), @response.body @@ -120,17 +122,17 @@ # Template can't be published on creation so do it afterward funder_template2.published = true funder_template2.save - + sign_in @researcher - + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: @funder.id}} assert_response :success assert_select "option", 3, "expected a dropdown with 2 templates and a 'please select' option" assert @response.body.include?("