Merge pull request #3622 from consul/use_dynamic_factories

Use dynamic attributes in factories
This commit is contained in:
Javier Martín
2019-08-07 20:31:25 +02:00
committed by GitHub
21 changed files with 330 additions and 340 deletions

View File

@@ -48,9 +48,6 @@ Performance/FixedSize:
Performance/FlatMap:
Enabled: true
Performance/LstripRstrip:
Enabled: true
Performance/RangeInclude:
Enabled: true
@@ -63,18 +60,12 @@ Performance/RedundantMatch:
Performance/RedundantMerge:
Enabled: true
Performance/RedundantSortBy:
Enabled: true
Performance/RegexpMatch:
Enabled: true
Performance/ReverseEach:
Enabled: true
Performance/Sample:
Enabled: true
Performance/Size:
Enabled: true
@@ -168,9 +159,6 @@ Rails/ReadWriteAttribute:
Rails/RedundantReceiverInWithOptions:
Enabled: true
Rails/RelativeDateConstant:
Enabled: true
Rails/RequestReferer:
Enabled: true
@@ -360,12 +348,6 @@ RSpec/VerifiedDoubles:
RSpec/VoidExpect:
Enabled: true
FactoryBot/StaticAttributeDefinedDynamically:
Enabled: true
FactoryBot/DynamicAttributeDefinedStatically:
Enabled: false
Security/Eval:
Enabled: true

View File

@@ -20,6 +20,9 @@ Capybara/FeatureMethods:
- scenario
- xscenario
FactoryBot/AttributeDefinedStatically:
Enabled: true
Layout/IndentationConsistency:
EnforcedStyle: rails
@@ -56,6 +59,9 @@ Rails/ApplicationRecord:
Rails/HttpPositionalArguments:
Enabled: true
Rails/RelativeDateConstant:
Enabled: true
RSpec/NotToNot:
Enabled: true

View File

@@ -96,8 +96,8 @@ group :development do
gem "capistrano3-delayed-job", "~> 1.7.3"
gem "erb_lint", require: false
gem "mdl", "~> 0.5.0", require: false
gem "rubocop", "~> 0.54.0", require: false
gem "rubocop-rspec", "~> 1.26.0", require: false
gem "rubocop", "~> 0.60.0", require: false
gem "rubocop-rspec", "~> 1.33.0", require: false
gem "rvm1-capistrano3", "~> 1.4.0", require: false
gem "scss_lint", "~> 0.55.0", require: false
gem "web-console", "~> 3.3.0"

View File

@@ -270,6 +270,7 @@ GEM
railties (>= 3.1, < 6.0)
invisible_captcha (0.10.0)
rails (>= 3.2.0)
jaro_winkler (1.5.2)
jquery-fileupload-rails (0.4.7)
actionpack (>= 3.1)
railties (>= 3.1)
@@ -370,10 +371,10 @@ GEM
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
parallel (1.12.1)
parallel (1.17.0)
paranoia (2.4.1)
activerecord (>= 4.0, < 5.3)
parser (2.5.1.2)
parser (2.6.3.0)
ast (~> 2.4.0)
pg (0.21.0)
pg_search (2.0.1)
@@ -447,16 +448,17 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.54.0)
rubocop (0.60.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.26.0)
rubocop (>= 0.53.0)
ruby-progressbar (1.10.0)
unicode-display_width (~> 1.4.0)
rubocop-rspec (1.33.0)
rubocop (>= 0.60.0)
ruby-progressbar (1.10.1)
rubyzip (1.2.2)
rvm1-capistrano3 (1.4.0)
capistrano (~> 3.0)
@@ -536,7 +538,7 @@ GEM
thread_safe (~> 0.1)
uglifier (4.1.19)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.0)
unicode-display_width (1.4.1)
unicorn (5.4.1)
kgio (~> 2.6)
raindrops (~> 0.7)
@@ -634,8 +636,8 @@ DEPENDENCIES
rinku (~> 2.0.2)
rollbar (~> 2.18.0)
rspec-rails (~> 3.8)
rubocop (~> 0.54.0)
rubocop-rspec (~> 1.26.0)
rubocop (~> 0.60.0)
rubocop-rspec (~> 1.33.0)
rvm1-capistrano3 (~> 1.4.0)
sass-rails (~> 5.0, >= 5.0.4)
savon (~> 2.12.0)

View File

@@ -10,7 +10,7 @@ FactoryBot.define do
sequence(:census_code) { |n| n.to_s }
trait :in_census do
census_code "01"
census_code { "01" }
end
end
@@ -20,12 +20,12 @@ FactoryBot.define do
target_url {["/proposals", "/debates" ].sample}
post_started_at { Time.current - 7.days }
post_ended_at { Time.current + 7.days }
background_color "#FF0000"
font_color "#FFFFFF"
background_color { "#FF0000" }
font_color { "#FFFFFF" }
end
factory :web_section do
name "homepage"
name { "homepage" }
end
factory :banner_section, class: "Banner::Section" do
@@ -34,33 +34,33 @@ FactoryBot.define do
end
factory :site_customization_page, class: "SiteCustomization::Page" do
slug "example-page"
title "Example page"
subtitle "About an example"
content "This page is about..."
more_info_flag false
print_content_flag false
status "draft"
slug { "example-page" }
title { "Example page" }
subtitle { "About an example" }
content { "This page is about..." }
more_info_flag { false }
print_content_flag { false }
status { "draft" }
trait :published do
status "published"
status { "published" }
end
trait :display_in_more_info do
more_info_flag true
more_info_flag { true }
end
end
factory :site_customization_content_block, class: "SiteCustomization::ContentBlock" do
name "top_links"
locale "en"
body "Some top links content"
name { "top_links" }
locale { "en" }
body { "Some top links content" }
end
factory :map_location do
latitude 51.48
longitude 0.0
zoom 10
latitude { 51.48 }
longitude { 0.0 }
zoom { 10 }
trait :proposal_map_location do
proposal
@@ -78,7 +78,7 @@ FactoryBot.define do
sequence(:link_url) { |n| "Link url #{n}" }
trait :header do
header true
header { true }
sequence(:button_text) { |n| "Button text #{n}" }
sequence(:button_url) { |n| "Button url #{n}" }
sequence(:alignment) { |n| "background" }
@@ -93,8 +93,8 @@ FactoryBot.define do
end
factory :i18n_content, class: "I18nContent" do
key "debates.index.section_footer.description"
value_es "Texto en español"
value_en "Text in english"
key { "debates.index.section_footer.description" }
value_es { "Texto en español" }
value_en { "Text in english" }
end
end

View File

@@ -1,59 +1,59 @@
FactoryBot.define do
factory :budget do
sequence(:name) { |n| "#{Faker::Lorem.word} #{n}" }
currency_symbol ""
phase "accepting"
description_drafting "This budget is drafting"
description_informing "This budget is informing"
description_accepting "This budget is accepting"
description_reviewing "This budget is reviewing"
description_selecting "This budget is selecting"
description_valuating "This budget is valuating"
description_publishing_prices "This budget is publishing prices"
description_balloting "This budget is balloting"
description_reviewing_ballots "This budget is reviewing ballots"
description_finished "This budget is finished"
currency_symbol { "" }
phase { "accepting" }
description_drafting { "This budget is drafting" }
description_informing { "This budget is informing" }
description_accepting { "This budget is accepting" }
description_reviewing { "This budget is reviewing" }
description_selecting { "This budget is selecting" }
description_valuating { "This budget is valuating" }
description_publishing_prices { "This budget is publishing prices" }
description_balloting { "This budget is balloting" }
description_reviewing_ballots { "This budget is reviewing ballots" }
description_finished { "This budget is finished" }
trait :drafting do
phase "drafting"
phase { "drafting" }
end
trait :informing do
phase "informing"
phase { "informing" }
end
trait :accepting do
phase "accepting"
phase { "accepting" }
end
trait :reviewing do
phase "reviewing"
phase { "reviewing" }
end
trait :selecting do
phase "selecting"
phase { "selecting" }
end
trait :valuating do
phase "valuating"
phase { "valuating" }
end
trait :publishing_prices do
phase "publishing_prices"
phase { "publishing_prices" }
end
trait :balloting do
phase "balloting"
phase { "balloting" }
end
trait :reviewing_ballots do
phase "reviewing_ballots"
phase { "reviewing_ballots" }
end
trait :finished do
phase "finished"
results_enabled true
stats_enabled true
phase { "finished" }
results_enabled { true }
stats_enabled { true }
end
end
@@ -68,12 +68,12 @@ FactoryBot.define do
factory :budget_heading, class: "Budget::Heading" do
sequence(:name) { |n| "Heading #{n}" }
price 1000000
population 1234
latitude "40.416775"
longitude "-3.703790"
price { 1000000 }
population { 1234 }
latitude { "40.416775" }
longitude { "-3.703790" }
transient { budget nil }
transient { budget { nil } }
group { association :budget_group, budget: budget || association(:budget) }
trait :drafting_budget do
@@ -85,64 +85,64 @@ FactoryBot.define do
sequence(:title) { |n| "Budget Investment #{n} title" }
heading { association :budget_heading, budget: budget }
association :author, factory: :user
description "Spend money on this"
price 10
unfeasibility_explanation ""
skip_map "1"
terms_of_service "1"
incompatible false
description { "Spend money on this" }
price { 10 }
unfeasibility_explanation { "" }
skip_map { "1" }
terms_of_service { "1" }
incompatible { false }
trait :with_confidence_score do
before(:save) { |i| i.calculate_confidence_score }
end
trait :feasible do
feasibility "feasible"
feasibility { "feasible" }
end
trait :unfeasible do
feasibility "unfeasible"
unfeasibility_explanation "set to unfeasible on creation"
feasibility { "unfeasible" }
unfeasibility_explanation { "set to unfeasible on creation" }
end
trait :undecided do
feasibility "undecided"
feasibility { "undecided" }
end
trait :finished do
valuation_finished true
valuation_finished { true }
end
trait :selected do
selected true
feasibility "feasible"
valuation_finished true
selected { true }
feasibility { "feasible" }
valuation_finished { true }
end
trait :winner do
selected
winner true
winner { true }
end
trait :visible_to_valuators do
visible_to_valuators true
visible_to_valuators { true }
end
trait :incompatible do
selected
incompatible true
incompatible { true }
end
trait :selected_with_price do
selected
price 1000
price_explanation "Because of reasons"
price { 1000 }
price_explanation { "Because of reasons" }
end
trait :unselected do
selected false
feasibility "feasible"
valuation_finished true
selected { false }
feasibility { "feasible" }
valuation_finished { true }
end
trait :hidden do
@@ -174,12 +174,12 @@ FactoryBot.define do
factory :budget_phase, class: "Budget::Phase" do
budget
kind :balloting
summary Faker::Lorem.sentence(3)
description Faker::Lorem.sentence(10)
kind { :balloting }
summary { Faker::Lorem.sentence(3) }
description { Faker::Lorem.sentence(10) }
starts_at { Date.yesterday }
ends_at { Date.tomorrow }
enabled true
enabled { true }
end
factory :budget_ballot, class: "Budget::Ballot" do
@@ -190,7 +190,7 @@ FactoryBot.define do
factory :budget_ballot_line, class: "Budget::Ballot::Line" do
association :investment, factory: :budget_investment
transient { user nil }
transient { user { nil } }
ballot do
association :budget_ballot, budget: investment.budget.reload, user: user || association(:user)
@@ -200,7 +200,7 @@ FactoryBot.define do
factory :budget_reclassified_vote, class: "Budget::ReclassifiedVote" do
user
association :investment, factory: :budget_investment
reason "unfeasible"
reason { "unfeasible" }
end
factory :valuator_group, class: ValuatorGroup do
@@ -209,7 +209,7 @@ FactoryBot.define do
factory :heading_content_block, class: "Budget::ContentBlock" do
association :heading, factory: :budget_heading
locale "en"
body "Some heading contents"
locale { "en" }
body { "Some heading contents" }
end
end

View File

@@ -3,16 +3,16 @@ FactoryBot.define do
sequence(:name) { |n| "Tag #{n} name" }
trait :category do
kind "category"
kind { "category" }
end
trait :milestone do
kind "milestone"
kind { "milestone" }
end
end
factory :tagging, class: "ActsAsTaggableOn::Tagging" do
context "tags"
context { "tags" }
association :taggable, factory: :proposal
tag
end

View File

@@ -27,7 +27,7 @@ FactoryBot.define do
end
trait :valuation do
valuation true
valuation { true }
association :commentable, factory: :budget_investment
before :create do |valuation|
valuator = create(:valuator)

View File

@@ -1,8 +1,8 @@
FactoryBot.define do
factory :debate do
sequence(:title) { |n| "Debate #{n} title" }
description "Debate description"
terms_of_service "1"
description { "Debate description" }
terms_of_service { "1" }
association :author, factory: :user
trait :hidden do

View File

@@ -1,7 +1,7 @@
FactoryBot.define do
factory :newsletter do
sequence(:subject) { |n| "Subject #{n}" }
segment_recipient UserSegments::SEGMENTS.sample
segment_recipient { UserSegments::SEGMENTS.sample }
sequence(:from) { |n| "noreply#{n}@consul.dev" }
sequence(:body) { |n| "Body #{n}" }
end

View File

@@ -1,7 +1,7 @@
FactoryBot.define do
factory :image do
attachment { File.new("spec/fixtures/files/clippy.jpg") }
title "Lorem ipsum dolor sit amet"
title { "Lorem ipsum dolor sit amet" }
association :user, factory: :user
trait :proposal_image do
@@ -31,7 +31,7 @@ FactoryBot.define do
end
trait :admin do
admin true
admin { true }
end
end
@@ -39,18 +39,18 @@ FactoryBot.define do
user
trait :proposal do
resource_type "Proposal"
resource_type { "Proposal" }
end
trait :budget_investment do
resource_type "Budget::Investment"
resource_type { "Budget::Investment" }
end
trait :documents do
resource_relation "documents"
resource_relation { "documents" }
attachment { File.new("spec/fixtures/files/empty.pdf") }
end
trait :image do
resource_relation "image"
resource_relation { "image" }
attachment { File.new("spec/fixtures/files/clippy.jpg") }
end
initialize_with { new(attributes) }

View File

@@ -1,8 +1,8 @@
FactoryBot.define do
factory :legislation_process, class: "Legislation::Process" do
title "A collaborative legislation process"
description "Description of the process"
summary "Summary of the process"
title { "A collaborative legislation process" }
description { "Description of the process" }
summary { "Summary of the process" }
start_date { Date.current - 5.days }
end_date { Date.current + 5.days }
@@ -16,13 +16,13 @@ FactoryBot.define do
people_proposals_phase_start_date { Date.current }
people_proposals_phase_end_date { Date.current + 2.days }
result_publication_date { Date.current + 5.days }
debate_phase_enabled true
allegations_phase_enabled true
proposals_phase_enabled true
people_proposals_phase_enabled true
draft_publication_enabled true
result_publication_enabled true
published true
debate_phase_enabled { true }
allegations_phase_enabled { true }
proposals_phase_enabled { true }
people_proposals_phase_enabled { true }
draft_publication_enabled { true }
result_publication_enabled { true }
published { true }
trait :past do
start_date { Date.current - 12.days }
@@ -40,7 +40,7 @@ FactoryBot.define do
end_date { Date.current + 5.days }
draft_start_date { Date.current - 2.days }
draft_end_date { Date.current + 2.days }
draft_phase_enabled true
draft_phase_enabled { true }
end
trait :in_debate_phase do
@@ -57,33 +57,33 @@ FactoryBot.define do
trait :in_proposals_phase do
proposals_phase_start_date { Date.current - 1.day }
proposals_phase_end_date { Date.current + 2.days }
proposals_phase_enabled true
proposals_phase_enabled { true }
end
trait :upcoming_proposals_phase do
proposals_phase_start_date { Date.current + 1.day }
proposals_phase_end_date { Date.current + 2.days }
proposals_phase_enabled true
proposals_phase_enabled { true }
end
trait :in_people_proposals_phase do
people_proposals_phase_start_date { Date.current - 1.day }
people_proposals_phase_end_date { Date.current + 2.days }
people_proposals_phase_enabled true
people_proposals_phase_enabled { true }
end
trait :upcoming_people_proposals_phase do
people_proposals_phase_start_date { Date.current + 1.day }
people_proposals_phase_end_date { Date.current + 2.days }
people_proposals_phase_enabled true
people_proposals_phase_enabled { true }
end
trait :published do
published true
published { true }
end
trait :not_published do
published false
published { false }
end
trait :open do
@@ -94,23 +94,23 @@ FactoryBot.define do
trait :empty do
start_date { Date.current - 5.days }
end_date { Date.current + 5.days }
debate_start_date nil
debate_end_date nil
draft_publication_date nil
allegations_start_date nil
allegations_end_date nil
proposals_phase_start_date nil
proposals_phase_end_date nil
people_proposals_phase_start_date nil
people_proposals_phase_end_date nil
result_publication_date nil
debate_phase_enabled false
allegations_phase_enabled false
proposals_phase_enabled false
people_proposals_phase_enabled false
draft_publication_enabled false
result_publication_enabled false
published true
debate_start_date { nil }
debate_end_date { nil }
draft_publication_date { nil }
allegations_start_date { nil }
allegations_end_date { nil }
proposals_phase_start_date { nil }
proposals_phase_end_date { nil }
people_proposals_phase_start_date { nil }
people_proposals_phase_end_date { nil }
result_publication_date { nil }
debate_phase_enabled { false }
allegations_phase_enabled { false }
proposals_phase_enabled { false }
people_proposals_phase_enabled { false }
draft_publication_enabled { false }
result_publication_enabled { false }
published { true }
end
trait :with_milestone_tags do
@@ -120,11 +120,11 @@ FactoryBot.define do
factory :legislation_draft_version, class: "Legislation::DraftVersion" do
process factory: :legislation_process
title "Version 1"
changelog "What changed in this version"
status "draft"
final_version false
body <<-LOREM_IPSUM
title { "Version 1" }
changelog { "What changed in this version" }
status { "draft" }
final_version { false }
body { <<-LOREM_IPSUM }
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.
@@ -139,29 +139,29 @@ Lorem salutandi eu mea, eam in soleat iriure assentior. Tamquam lobortis id qui.
LOREM_IPSUM
trait :published do
status "published"
status { "published" }
end
trait :final_version do
final_version true
final_version { true }
end
end
factory :legislation_annotation, class: "Legislation::Annotation" do
draft_version factory: :legislation_draft_version
author factory: :user
quote "ipsum"
text "a comment"
ranges [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]
range_start "/p[1]"
range_start_offset 6
range_end "/p[1]"
range_end_offset 11
quote { "ipsum" }
text { "a comment" }
ranges { [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}] }
range_start { "/p[1]" }
range_start_offset { 6 }
range_end { "/p[1]" }
range_end_offset { 11 }
end
factory :legislation_question, class: "Legislation::Question" do
process factory: :legislation_process
title "Question text"
title { "Question text" }
author factory: :user
end
@@ -178,55 +178,55 @@ LOREM_IPSUM
factory :legislation_proposal, class: "Legislation::Proposal" do
sequence(:title) { |n| "Proposal #{n} for a legislation" }
summary "This law should include..."
terms_of_service "1"
summary { "This law should include..." }
terms_of_service { "1" }
process factory: :legislation_process
author factory: :user
end
factory :debate_comment, class: "Comment" do
commentable_id "10"
commentable_type Legislation::Question
body "This is a comment"
user_id "1"
cached_votes_down "0"
cached_votes_total "0"
cached_votes_up "0"
confidence_score "0"
commentable_id { "10" }
commentable_type { Legislation::Question }
body { "This is a comment" }
user_id { "1" }
cached_votes_down { "0" }
cached_votes_total { "0" }
cached_votes_up { "0" }
confidence_score { "0" }
end
factory :text_comment, class: "Comment" do
commentable_id "10"
commentable_type Legislation::Annotation
body "This is a comment"
user_id "1"
cached_votes_down "0"
cached_votes_total "0"
cached_votes_up "0"
confidence_score "0"
ancestry nil
commentable_id { "10" }
commentable_type { Legislation::Annotation }
body { "This is a comment" }
user_id { "1" }
cached_votes_down { "0" }
cached_votes_total { "0" }
cached_votes_up { "0" }
confidence_score { "0" }
ancestry { nil }
end
factory :legislation_people_proposal, class: "Legislation::PeopleProposal" do
sequence(:title) { |n| "People and group #{n} for a legislation" }
summary "This law should be implemented by..."
terms_of_service "1"
summary { "This law should be implemented by..." }
terms_of_service { "1" }
process factory: :legislation_process
author factory: :user
validated false
validated { false }
trait :with_contact_info do
email "proposal@test.com"
website "https://proposal.io"
phone "666666666"
facebook "facebook.id"
twitter "TwitterId"
youtube "youtubechannelid"
instagram "instagramid"
email { "proposal@test.com" }
website { "https://proposal.io" }
phone { "666666666" }
facebook { "facebook.id" }
twitter { "TwitterId" }
youtube { "youtubechannelid" }
instagram { "instagramid" }
end
trait :validated do
validated true
validated { true }
end
end
end

View File

@@ -8,17 +8,17 @@ FactoryBot.define do
association :milestoneable, factory: :budget_investment
association :status, factory: :milestone_status
sequence(:title) { |n| "Milestone #{n} title" }
description "Milestone description"
description { "Milestone description" }
publication_date { Date.current }
end
factory :progress_bar do
association :progressable, factory: :budget_investment
percentage { rand(0..100) }
kind :primary
kind { :primary }
trait(:secondary) do
kind :secondary
kind { :secondary }
sequence(:title) { |n| "Progress bar #{n} title" }
end
end

View File

@@ -11,13 +11,13 @@ FactoryBot.define do
factory :admin_notification do
title { |n| "Admin Notification title #{n}" }
body { |n| "Admin Notification body #{n}" }
link nil
segment_recipient UserSegments::SEGMENTS.sample
recipients_count nil
sent_at nil
link { nil }
segment_recipient { UserSegments::SEGMENTS.sample }
recipients_count { nil }
sent_at { nil }
trait :sent do
recipients_count 1
recipients_count { 1 }
sent_at { Time.current }
end
end

View File

@@ -1,7 +1,7 @@
FactoryBot.define do
factory :organization do
user
responsible_name "Johnny Utah"
responsible_name { "Johnny Utah" }
sequence(:name) { |n| "org#{n}" }
trait :verified do

View File

@@ -2,7 +2,7 @@ FactoryBot.define do
factory :poll do
sequence(:name) { |n| "Poll #{SecureRandom.hex}" }
slug "this-is-a-slug"
slug { "this-is-a-slug" }
starts_at { 1.month.ago }
ends_at { 1.month.from_now }
@@ -23,7 +23,7 @@ FactoryBot.define do
end
trait :published do
published true
published { true }
end
end
@@ -112,8 +112,8 @@ FactoryBot.define do
factory :poll_answer_video, class: "Poll::Question::Answer::Video" do
association :answer, factory: :poll_question_answer
title "Sample video title"
url "https://youtu.be/nhuNb0XtRhQ"
title { "Sample video title" }
url { "https://youtu.be/nhuNb0XtRhQ" }
end
factory :poll_booth, class: "Poll::Booth" do
@@ -132,7 +132,7 @@ FactoryBot.define do
date { Date.current }
trait :final do
final true
final { true }
end
end
@@ -142,11 +142,11 @@ FactoryBot.define do
date { Date.current }
trait :vote_collection_task do
task 0
task { 0 }
end
trait :recount_scrutiny_task do
task 1
task { 1 }
end
end
@@ -154,16 +154,16 @@ FactoryBot.define do
association :user, :level_two
from_web
transient { budget nil }
transient { budget { nil } }
poll { budget&.poll || association(:poll, budget: budget) }
trait :from_web do
origin "web"
token SecureRandom.hex(32)
origin { "web" }
token { SecureRandom.hex(32) }
end
trait :from_booth do
origin "booth"
origin { "booth" }
booth_assignment do
association :poll_booth_assignment, poll: poll
@@ -177,13 +177,13 @@ FactoryBot.define do
end
trait :valid_document do
document_type "1"
document_number "12345678Z"
document_type { "1" }
document_number { "12345678Z" }
end
trait :invalid_document do
document_type "1"
document_number "99999999A"
document_type { "1" }
document_number { "99999999A" }
end
end
@@ -196,18 +196,18 @@ FactoryBot.define do
factory :poll_partial_result, class: "Poll::PartialResult" do
association :question, factory: [:poll_question, :with_answers]
association :author, factory: :user
origin "web"
origin { "web" }
answer { question.question_answers.sample.title }
end
factory :poll_recount, class: "Poll::Recount" do
association :author, factory: :user
origin "web"
origin { "web" }
trait :from_booth do
origin "booth"
origin { "booth" }
transient { poll nil }
transient { poll { nil } }
booth_assignment do
association :poll_booth_assignment, poll: poll
@@ -218,20 +218,20 @@ FactoryBot.define do
factory :poll_ballot_sheet, class: "Poll::BallotSheet" do
association :poll
association :officer_assignment, factory: :poll_officer_assignment
data "1234;9876;5678\n1000;2000;3000;9999"
data { "1234;9876;5678\n1000;2000;3000;9999" }
end
factory :poll_ballot, class: "Poll::Ballot" do
association :ballot_sheet, factory: :poll_ballot_sheet
data "1,2,3"
data { "1,2,3" }
end
factory :officing_residence, class: "Officing::Residence" do
user
association :officer, factory: :poll_officer
document_number
document_type "1"
year_of_birth "1980"
document_type { "1" }
year_of_birth { "1980" }
trait :invalid do
year_of_birth { Time.current.year }

View File

@@ -2,11 +2,11 @@ FactoryBot.define do
factory :proposal do
sequence(:title) { |n| "Proposal #{n} title" }
sequence(:summary) { |n| "In summary, what we want is... #{n}" }
description "Proposal description"
video_url "https://youtu.be/nhuNb0XtRhQ"
responsible_name "John Snow"
terms_of_service "1"
skip_map "1"
description { "Proposal description" }
video_url { "https://youtu.be/nhuNb0XtRhQ" }
responsible_name { "John Snow" }
terms_of_service { "1" }
skip_map { "1" }
published_at { Time.current }
association :author, factory: :user
@@ -34,7 +34,7 @@ FactoryBot.define do
end
trait :selected do
selected true
selected { true }
end
trait :with_hot_score do
@@ -57,13 +57,13 @@ FactoryBot.define do
end
trait :draft do
published_at nil
published_at { nil }
end
trait :retired do
retired_at { Time.current }
retired_reason "unfeasible"
retired_explanation "Retired explanation"
retired_reason { "unfeasible" }
retired_explanation { "Retired explanation" }
end
trait :published do
@@ -82,7 +82,7 @@ FactoryBot.define do
association :author, factory: :user
trait :moderated do
moderated true
moderated { true }
end
trait :ignored do
@@ -101,7 +101,7 @@ FactoryBot.define do
factory :signature_sheet do
association :signable, factory: :proposal
association :author, factory: :user
required_fields_to_verify "123A, 456B, 789C"
required_fields_to_verify { "123A, 456B, 789C" }
end
factory :signature do
@@ -111,24 +111,24 @@ FactoryBot.define do
factory :activity do
user
action "hide"
action { "hide" }
association :actionable, factory: :proposal
end
factory :dashboard_action, class: "Dashboard::Action" do
title { Faker::Lorem.sentence[0..79] }
description { Faker::Lorem.sentence }
link nil
request_to_administrators true
day_offset 0
required_supports 0
order 0
active true
hidden_at nil
action_type "proposed_action"
link { nil }
request_to_administrators { true }
day_offset { 0 }
required_supports { 0 }
order { 0 }
active { true }
hidden_at { nil }
action_type { "proposed_action" }
trait :admin_request do
request_to_administrators true
request_to_administrators { true }
end
trait :external_link do
@@ -136,11 +136,11 @@ FactoryBot.define do
end
trait :inactive do
active false
active { false }
end
trait :active do
active true
active { true }
end
trait :deleted do
@@ -148,11 +148,11 @@ FactoryBot.define do
end
trait :proposed_action do
action_type "proposed_action"
action_type { "proposed_action" }
end
trait :resource do
action_type "resource"
action_type { "resource" }
end
end

View File

@@ -3,11 +3,11 @@ FactoryBot.define do
sequence(:username) { |n| "Manuela#{n}" }
sequence(:email) { |n| "manuela#{n}@consul.dev" }
password "judgmentday"
terms_of_service "1"
password { "judgmentday" }
terms_of_service { "1" }
confirmed_at { Time.current }
date_of_birth { 20.years.ago }
public_activity true
public_activity { true }
trait :incomplete_verification do
after :create do |user|
@@ -17,19 +17,19 @@ FactoryBot.define do
trait :level_two do
residence_verified_at { Time.current }
unconfirmed_phone "611111111"
confirmed_phone "611111111"
sms_confirmation_code "1234"
document_type "1"
unconfirmed_phone { "611111111" }
confirmed_phone { "611111111" }
sms_confirmation_code { "1234" }
document_type { "1" }
document_number
date_of_birth Date.new(1980, 12, 31)
gender "female"
date_of_birth { Date.new(1980, 12, 31) }
gender { "female" }
geozone
end
trait :level_three do
verified_at { Time.current }
document_type "1"
document_type { "1" }
document_number
end
@@ -47,16 +47,16 @@ FactoryBot.define do
end
trait :in_census do
document_number "12345678Z"
document_type "1"
document_number { "12345678Z" }
document_type { "1" }
verified_at { Time.current }
end
end
factory :identity do
user nil
provider "Twitter"
uid "MyString"
user { nil }
provider { "Twitter" }
uid { "MyString" }
end
factory :administrator do
@@ -96,8 +96,8 @@ FactoryBot.define do
end
factory :direct_message do
title "Hey"
body "How are You doing?"
title { "Hey" }
body { "How are You doing?" }
association :sender, factory: :user
association :receiver, factory: :user
end

View File

@@ -1,9 +1,9 @@
FactoryBot.define do
factory :local_census_record, class: "LocalCensusRecord" do
sequence(:document_number) { |n| "DOC_NUMBER#{n}" }
document_type 1
date_of_birth Date.new(1970, 1, 31)
postal_code "28002"
document_type { 1 }
date_of_birth { Date.new(1970, 1, 31) }
postal_code { "28002" }
end
factory :local_census_records_import, class: "LocalCensusRecords::Import" do
file {
@@ -17,50 +17,50 @@ FactoryBot.define do
factory :verification_residence, class: Verification::Residence do
user
document_number
document_type "1"
document_type { "1" }
date_of_birth { Time.zone.local(1980, 12, 31).to_date }
postal_code "28013"
terms_of_service "1"
postal_code { "28013" }
terms_of_service { "1" }
trait :invalid do
postal_code "28001"
postal_code { "28001" }
end
end
factory :failed_census_call do
user
document_number
document_type 1
date_of_birth Date.new(1900, 1, 1)
postal_code "28000"
document_type { 1 }
date_of_birth { Date.new(1900, 1, 1) }
postal_code { "28000" }
end
factory :verification_sms, class: Verification::Sms do
phone "699999999"
phone { "699999999" }
end
factory :verification_letter, class: Verification::Letter do
user
email "user@consul.dev"
password "1234"
verification_code "5555"
email { "user@consul.dev" }
password { "1234" }
verification_code { "5555" }
end
factory :lock do
user
tries 0
tries { 0 }
locked_until { Time.current }
end
factory :verified_user do
document_number
document_type "dni"
document_type { "dni" }
end
factory :verification_document, class: Verification::Management::Document do
document_number
document_type "1"
date_of_birth Date.new(1980, 12, 31)
postal_code "28013"
document_type { "1" }
date_of_birth { Date.new(1980, 12, 31) }
postal_code { "28013" }
end
end

View File

@@ -1,76 +1,76 @@
FactoryBot.define do
factory :votation_type do
factory :votation_type_unique do
enum_type "unique"
open_answer false
prioritized false
enum_type { "unique" }
open_answer { false }
prioritized { false }
end
factory :votation_type_multiple do
enum_type "multiple"
open_answer false
prioritized false
max_votes 5
enum_type { "multiple" }
open_answer { false }
prioritized { false }
max_votes { 5 }
end
factory :votation_type_prioritized do
enum_type "prioritized"
open_answer false
prioritized true
max_votes 5
prioritization_type "borda"
enum_type { "prioritized" }
open_answer { false }
prioritized { true }
max_votes { 5 }
prioritization_type { "borda" }
end
factory :votation_type_positive_open do
enum_type "positive_open"
open_answer true
prioritized false
max_votes 5
enum_type { "positive_open" }
open_answer { true }
prioritized { false }
max_votes { 5 }
end
factory :votation_type_positive_negative_open do
enum_type "positive_negative_open"
open_answer true
prioritized false
max_votes 5
prioritization_type "borda"
enum_type { "positive_negative_open" }
open_answer { true }
prioritized { false }
max_votes { 5 }
prioritization_type { "borda" }
end
factory :votation_type_answer_couples_open do
enum_type "answer_couples_open"
open_answer true
prioritized false
max_votes 5
enum_type { "answer_couples_open" }
open_answer { true }
prioritized { false }
max_votes { 5 }
end
factory :votation_type_answer_couples_closed do
enum_type "answer_couples_open"
open_answer false
prioritized false
max_votes 5
enum_type { "answer_couples_open" }
open_answer { false }
prioritized { false }
max_votes { 5 }
end
factory :votation_type_answer_set_open do
enum_type "answer_set_open"
open_answer true
prioritized false
max_votes 3
max_groups_answers 5
enum_type { "answer_set_open" }
open_answer { true }
prioritized { false }
max_votes { 3 }
max_groups_answers { 5 }
end
factory :votation_type_answer_set_closed do
enum_type "answer_set_open"
open_answer false
prioritized false
max_votes 3
max_groups_answers 5
enum_type { "answer_set_open" }
open_answer { false }
prioritized { false }
max_votes { 3 }
max_groups_answers { 5 }
end
trait :open do
open_answer true
open_answer { true }
end
trait :prioritized do
prioritized true
prioritized { true }
end
end

View File

@@ -2,7 +2,7 @@ FactoryBot.define do
factory :vote do
association :votable, factory: :debate
association :voter, factory: :user
vote_flag true
vote_flag { true }
after(:create) do |vote, _|
vote.votable.update_cached_votes
end