Skip to content

Commit

Permalink
fixed up rubocop issues in spec/. removed redundant org_date_rangeabl…
Browse files Browse the repository at this point in the history
…e_spec in favor of models/concerns/date_rangeable_spec
  • Loading branch information
briri committed Jul 10, 2020
1 parent 44c1daa commit 662c980
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 199 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ AllCops:
# Show the name of the cops being voilated in the feedback
DisplayCopNames: true
DisplayStyleGuide: true
# We're using Ruby 2.4 right now. So force that version or higher.
TargetRubyVersion: 2.4
# We're using Ruby 2.6 right now. So force that version or higher.
TargetRubyVersion: 2.6
# Don't check these files. So many of them are boilerplate code with violations.
Exclude:
- 'bin/*'
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/concerns/org_selectable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class StubController < ApplicationController
OrgSelection::HashToOrgService.stubs(:to_identifiers)
.returns([build(:identifier)])

org_id = { id: Faker::Number.number, name: Faker::Company.name }.to_json
@params = ActionController::Parameters.new({
other_param: Faker::Company.name,
org_id: { id: Faker::Number.number, name: Faker::Company.name }.to_json,
org_id: org_id,
org_name: Faker::Company.name,
org_sources: [Faker::Company.name],
org_crosswalk: [{ id: Faker::Number.number }]
Expand Down
4 changes: 3 additions & 1 deletion spec/factories/templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
end

after(:create) do |template, evaluator|
create_list(:phase, evaluator.phases, template: template, sections: evaluator.sections, questions: evaluator.questions)
create_list(:phase, evaluator.phases, template: template,
sections: evaluator.sections,
questions: evaluator.questions)
end

end
Expand Down
9 changes: 5 additions & 4 deletions spec/features/annotations/annotations_editing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
click_link section.title

within("fieldset#fields_annotation_#{template.annotation_ids.last}") do
tinymce_fill_in("question_annotations_attributes_annotation_#{template.annotation_ids.last}_text", with: "Noo bar")
id = "question_annotations_attributes_annotation_#{template.annotation_ids.last}_text"
tinymce_fill_in(id, with: "Noo bar")
end
question = Question.last

# NOTE: This is question 2, since Annotation was copied upon clicking "Customise"
within("#edit_question_#{template.question_ids.last}") do
# Expect it to destroy the newly cleared Annotation
Expand All @@ -73,8 +74,8 @@
click_link section.title
# NOTE: This is annotation 2, since Annotation was copied upon clicking "Customise"
within("fieldset#fields_annotation_#{template.annotation_ids.last}") do
tinymce_fill_in(:"question_annotations_attributes_annotation_#{template.annotation_ids.last}_text",
with: " ")
id = "question_annotations_attributes_annotation_#{template.annotation_ids.last}_text"
tinymce_fill_in(:"#{id}", with: " ")
end
# NOTE: This is question 2, since Annotation was copied upon clicking "Customise"
within("#edit_question_#{template.question_ids.last}") do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/plans/exports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

scenario "User downloads org plan belonging to User in same org" do
new_plan = create(:plan, :organisationally_visible, template: template)
role = create(:role, :creator, plan: new_plan, user: create(:user, org: org))
create(:role, :creator, plan: new_plan, user: create(:user, org: org))
sign_in(user)
within("#plan_#{plan.id}") do
click_button("Actions")
Expand All @@ -67,14 +67,14 @@

scenario "User downloads org plan belonging to User in other org" do
new_plan = create(:plan, :organisationally_visible, template: template)
role = create(:role, :creator, plan: new_plan)
create(:role, :creator, plan: new_plan)
sign_in(create(:user))
expect(page).not_to have_text(new_plan.title)
end

scenario "User attempts to download private plan belonging to User in same" do
new_plan = create(:plan, :privately_visible, template: template)
role = create(:role, :creator, plan: new_plan)
create(:role, :creator, plan: new_plan)
sign_in(create(:user))
expect(page).not_to have_text(new_plan.title)
end
Expand Down
94 changes: 47 additions & 47 deletions spec/features/plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# <value-pairs value-pairs-name="H2020projects" dc-term="relation">
# <pair>
# <displayed-value>
# 115797 - INNODIA - Translational approaches to disease modifying therapy of type 1 diabetes: an innovative approach towards understanding and arresting type 1 diabetes – Sofia ref.: 115797
# 115797 - INNODIA - Translational approaches to disease modifying therapy of ...
# </displayed-value>
# <stored-value>info:eu-repo/grantAgreement/EC/H2020/115797/EU</stored-value>
# </pair>
Expand All @@ -29,55 +29,55 @@
# )
end

scenario "User creates a new Plan", :js do
xit "User creates a new Plan", :js do
# TODO: Revisit this after we start refactoring/building out or tests for
# the new create plan workflow. For some reason the plans/new.js isn't
# firing here but works fine in the UI with manual testing
# # Action
# click_link "Create plan"
# fill_in :plan_title, with: "My test plan"
# fill_in :org_org_name, with: @research_org.name
# choose_suggestion(@research_org.name)
#
# fill_in :funder_org_name, with: @funding_org.name
# choose_suggestion(@funding_org.name)
# click_button "Create plan"
#
# # Expectations
# expect(@user.plans).to be_one
# @plan = Plan.last
# expect(current_path).to eql(plan_path(@plan))
#
# ##
# # User updates plan content...
#
# # Action
# expect(page).to have_css("input[type=text][value='#{@plan.title}']")
#
# within "#edit_plan_#{@plan.id}" do
# fill_in "Grant number", with: "Innodia"
# fill_in "Project abstract", with: "Plan abstract..."
# fill_in "ID", with: "ABCDEF"
# fill_in "ORCID iD", with: "My ORCID"
# fill_in "Phone", with: "07787 000 0000"
# click_button "Save"
# end
#
# # Reload the plan to get the latest from memory
# @plan.reload
#
# expect(current_path).to eql(overview_plan_path(@plan))
# expect(@plan.title).to eql("My test plan")
# expect(@plan.org_id).to eql(@research_org.id)
# expect(@plan.funder_id).to eql(@funding_org.id)
# expect(@plan.grant_number).to eql("115797")
# expect(@plan.description).to eql("Plan abstract...")
# expect(@plan.identifier).to eql("ABCDEF")
# name = [@user.firstname, @user.surname].join(" ")
# expect(@plan.principal_investigator).to eql(name)
# expect(@plan.principal_investigator_identifier).to eql("My ORCID")
# expect(@plan.principal_investigator_email).to eql(@user.email)
# expect(@plan.principal_investigator_phone).to eql("07787 000 0000")
# Action
click_link "Create plan"
fill_in :plan_title, with: "My test plan"
fill_in :org_org_name, with: @research_org.name
choose_suggestion(@research_org.name)

fill_in :funder_org_name, with: @funding_org.name
choose_suggestion(@funding_org.name)
click_button "Create plan"

# Expectations
expect(@user.plans).to be_one
@plan = Plan.last
expect(current_path).to eql(plan_path(@plan))

##
# User updates plan content...

# Action
expect(page).to have_css("input[type=text][value='#{@plan.title}']")

within "#edit_plan_#{@plan.id}" do
fill_in "Grant number", with: "Innodia"
fill_in "Project abstract", with: "Plan abstract..."
fill_in "ID", with: "ABCDEF"
fill_in "ORCID iD", with: "My ORCID"
fill_in "Phone", with: "07787 000 0000"
click_button "Save"
end

# Reload the plan to get the latest from memory
@plan.reload

expect(current_path).to eql(overview_plan_path(@plan))
expect(@plan.title).to eql("My test plan")
expect(@plan.org_id).to eql(@research_org.id)
expect(@plan.funder_id).to eql(@funding_org.id)
expect(@plan.grant_number).to eql("115797")
expect(@plan.description).to eql("Plan abstract...")
expect(@plan.identifier).to eql("ABCDEF")
name = [@user.firstname, @user.surname].join(" ")
expect(@plan.principal_investigator).to eql(name)
expect(@plan.principal_investigator_identifier).to eql("My ORCID")
expect(@plan.principal_investigator_email).to eql(@user.email)
expect(@plan.principal_investigator_phone).to eql("07787 000 0000")
end

end
4 changes: 0 additions & 4 deletions spec/features/registrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
let(:user_attributes) { attributes_for(:user) }

scenario "User creates a new acccount", :js do
user_count = User.count

# Setup
visit root_path

Expand All @@ -34,8 +32,6 @@
end

scenario "User attempts to create a new acccount with invalid atts", :js do
user_count = User.count

# Setup
visit root_path

Expand Down
6 changes: 3 additions & 3 deletions spec/features/super_admins/orgs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
find("table .dropdown-toggle").click
find(".dropdown-menu > li > a").click
nbr_links = all(".link").length
addLink
add_link
expect(all(".link").length).to eql(nbr_links + 1)
end

Expand All @@ -39,9 +39,9 @@
# Edit the first org in the table
find("table .dropdown-toggle").click
find(".dropdown-menu > li > a").click
addLink
add_link
nbr_links = all(".link").length
removeLink
remove_link
expect(all(".link").length).to eql(nbr_links - 1)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/features/templates/templates_editings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
end
click_link template.sections.first.title
within("#edit_question_#{template.question_ids.first}") do
textarea_id = page.body.match(/question\_annotations\_attributes\_annotation\_(\d+)\_text/)
tinymce_fill_in(:"question_annotations_attributes_annotation_#{Regexp.last_match(1)}_text", with: "Foo bar")
id = "question_annotations_attributes_annotation_#{Regexp.last_match(1)}_text"
tinymce_fill_in(:"#{id}", with: "Foo bar")
click_button "Save"
end
# Make sure annotation has been updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
visit organisational_org_admin_templates_path

click_button "Actions"
expect { click_link "Publish changes" }.to change { Template.last.published? }.from(false).to(true)
target = Template.last.published?
expect { click_link "Publish changes" }.to change { target }.from(false).to(true)

# Go back to the original Org...

Expand Down
2 changes: 1 addition & 1 deletion spec/models/identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

it "prevents duplicate value when identifier_scheme is nil" do
scheme = create(:identifier_scheme)
create(:identifier_scheme)
create(:identifier, identifiable: @org, identifier_scheme: nil,
value: "foo")
id = build(:identifier, identifiable: @org, identifier_scheme: nil,
Expand Down
8 changes: 5 additions & 3 deletions spec/models/org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@

it { should have_many(:annotations) }

# rubocop:disable Layout/LineLength
it { should have_and_belong_to_many(:token_permission_types).join_table("org_token_permissions") }
# rubocop:enable Layout/LineLength

it { should have_many(:identifiers) }

Expand Down Expand Up @@ -384,7 +386,7 @@

end

context "when user belongs to Org and plan user with role :editor, but not :creator and :administrator" do
context "user belongs to Org and plan user with role :editor, but not :creator and :admin" do

before do
plan.add_user!(user.id, :editor)
Expand All @@ -394,7 +396,7 @@

end

context "when user belongs to Org and plan user with role :commenter, but not :creator and :administrator" do
context "user belongs to Org and plan user with role :commenter, but not :creator and :admin" do

before do
plan.add_user!(user.id, :commenter)
Expand All @@ -404,7 +406,7 @@

end

context "when user belongs to Org and plan user with role :reviewer, but not :creator and :administrator" do
context "user belongs to Org and plan user with role :reviewer, but not :creator and :admin" do

before do
plan.add_user!(user.id, :reviewer)
Expand Down
2 changes: 2 additions & 0 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@

let!(:question_format) { create(:question_format, option_based: true) }

# rubocop:disable Metrics/LineLength
it {
expect do
create(:question, question_format: question_format, options: 0)
end.to raise_error(ActiveRecord::RecordInvalid,
"Validation failed: You must have at least one option with accompanying text.")
}
# rubocop:enable Metrics/LineLength

it { is_expected.to eql(true) }

Expand Down
7 changes: 5 additions & 2 deletions spec/models/section_sorter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe SectionSorter, type: :model doStubSection = Struct.new(:number, :modifiable, :id) do
RSpec.describe SectionSorter, type: :model do

StubSection = Struct.new(:number, :modifiable, :id) do

alias modifiable? modifiable
alias_method :modifiable?, :modifiable

def unmodifiable?
!modifiable?
Expand Down
10 changes: 5 additions & 5 deletions spec/models/stat_created_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
end

it "retrieves JSON details as a hash object" do
september = FactoryBot.create(:stat_created_plan,
date: "2018-09-30",
org: org,
count: 20,
details: details)
FactoryBot.create(:stat_created_plan,
date: "2018-09-30",
org: org,
count: 20,
details: details)

json_details = described_class.find_by_date("2018-09-30").details

Expand Down
6 changes: 4 additions & 2 deletions spec/models/stat_joined_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
context "when instances" do
let(:org) { FactoryBot.create(:org) }
it "returns instances in a comma-separated row" do
may = FactoryBot.create(:stat_joined_user, date: Date.new(2018, 0o5, 31), org: org, count: 20)
june = FactoryBot.create(:stat_joined_user, date: Date.new(2018, 0o6, 30), org: org, count: 10)
may = FactoryBot.create(:stat_joined_user, date: Date.new(2018, 0o5, 31),
org: org, count: 20)
june = FactoryBot.create(:stat_joined_user, date: Date.new(2018, 0o6, 30),
org: org, count: 10)
data = [may, june]

csv = described_class.to_csv(data)
Expand Down
Loading

0 comments on commit 662c980

Please sign in to comment.