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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,8 +1,8 @@
FactoryBot.define do FactoryBot.define do
factory :legislation_process, class: "Legislation::Process" do factory :legislation_process, class: "Legislation::Process" do
title "A collaborative legislation process" title { "A collaborative legislation process" }
description "Description of the process" description { "Description of the process" }
summary "Summary of the process" summary { "Summary of the process" }
start_date { Date.current - 5.days } start_date { Date.current - 5.days }
end_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_start_date { Date.current }
people_proposals_phase_end_date { Date.current + 2.days } people_proposals_phase_end_date { Date.current + 2.days }
result_publication_date { Date.current + 5.days } result_publication_date { Date.current + 5.days }
debate_phase_enabled true debate_phase_enabled { true }
allegations_phase_enabled true allegations_phase_enabled { true }
proposals_phase_enabled true proposals_phase_enabled { true }
people_proposals_phase_enabled true people_proposals_phase_enabled { true }
draft_publication_enabled true draft_publication_enabled { true }
result_publication_enabled true result_publication_enabled { true }
published true published { true }
trait :past do trait :past do
start_date { Date.current - 12.days } start_date { Date.current - 12.days }
@@ -40,7 +40,7 @@ FactoryBot.define do
end_date { Date.current + 5.days } end_date { Date.current + 5.days }
draft_start_date { Date.current - 2.days } draft_start_date { Date.current - 2.days }
draft_end_date { Date.current + 2.days } draft_end_date { Date.current + 2.days }
draft_phase_enabled true draft_phase_enabled { true }
end end
trait :in_debate_phase do trait :in_debate_phase do
@@ -57,33 +57,33 @@ FactoryBot.define do
trait :in_proposals_phase do trait :in_proposals_phase do
proposals_phase_start_date { Date.current - 1.day } proposals_phase_start_date { Date.current - 1.day }
proposals_phase_end_date { Date.current + 2.days } proposals_phase_end_date { Date.current + 2.days }
proposals_phase_enabled true proposals_phase_enabled { true }
end end
trait :upcoming_proposals_phase do trait :upcoming_proposals_phase do
proposals_phase_start_date { Date.current + 1.day } proposals_phase_start_date { Date.current + 1.day }
proposals_phase_end_date { Date.current + 2.days } proposals_phase_end_date { Date.current + 2.days }
proposals_phase_enabled true proposals_phase_enabled { true }
end end
trait :in_people_proposals_phase do trait :in_people_proposals_phase do
people_proposals_phase_start_date { Date.current - 1.day } people_proposals_phase_start_date { Date.current - 1.day }
people_proposals_phase_end_date { Date.current + 2.days } people_proposals_phase_end_date { Date.current + 2.days }
people_proposals_phase_enabled true people_proposals_phase_enabled { true }
end end
trait :upcoming_people_proposals_phase do trait :upcoming_people_proposals_phase do
people_proposals_phase_start_date { Date.current + 1.day } people_proposals_phase_start_date { Date.current + 1.day }
people_proposals_phase_end_date { Date.current + 2.days } people_proposals_phase_end_date { Date.current + 2.days }
people_proposals_phase_enabled true people_proposals_phase_enabled { true }
end end
trait :published do trait :published do
published true published { true }
end end
trait :not_published do trait :not_published do
published false published { false }
end end
trait :open do trait :open do
@@ -94,23 +94,23 @@ FactoryBot.define do
trait :empty do trait :empty do
start_date { Date.current - 5.days } start_date { Date.current - 5.days }
end_date { Date.current + 5.days } end_date { Date.current + 5.days }
debate_start_date nil debate_start_date { nil }
debate_end_date nil debate_end_date { nil }
draft_publication_date nil draft_publication_date { nil }
allegations_start_date nil allegations_start_date { nil }
allegations_end_date nil allegations_end_date { nil }
proposals_phase_start_date nil proposals_phase_start_date { nil }
proposals_phase_end_date nil proposals_phase_end_date { nil }
people_proposals_phase_start_date nil people_proposals_phase_start_date { nil }
people_proposals_phase_end_date nil people_proposals_phase_end_date { nil }
result_publication_date nil result_publication_date { nil }
debate_phase_enabled false debate_phase_enabled { false }
allegations_phase_enabled false allegations_phase_enabled { false }
proposals_phase_enabled false proposals_phase_enabled { false }
people_proposals_phase_enabled false people_proposals_phase_enabled { false }
draft_publication_enabled false draft_publication_enabled { false }
result_publication_enabled false result_publication_enabled { false }
published true published { true }
end end
trait :with_milestone_tags do trait :with_milestone_tags do
@@ -120,11 +120,11 @@ FactoryBot.define do
factory :legislation_draft_version, class: "Legislation::DraftVersion" do factory :legislation_draft_version, class: "Legislation::DraftVersion" do
process factory: :legislation_process process factory: :legislation_process
title "Version 1" title { "Version 1" }
changelog "What changed in this version" changelog { "What changed in this version" }
status "draft" status { "draft" }
final_version false final_version { false }
body <<-LOREM_IPSUM 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. 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. 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 LOREM_IPSUM
trait :published do trait :published do
status "published" status { "published" }
end end
trait :final_version do trait :final_version do
final_version true final_version { true }
end end
end end
factory :legislation_annotation, class: "Legislation::Annotation" do factory :legislation_annotation, class: "Legislation::Annotation" do
draft_version factory: :legislation_draft_version draft_version factory: :legislation_draft_version
author factory: :user author factory: :user
quote "ipsum" quote { "ipsum" }
text "a comment" text { "a comment" }
ranges [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}] ranges { [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}] }
range_start "/p[1]" range_start { "/p[1]" }
range_start_offset 6 range_start_offset { 6 }
range_end "/p[1]" range_end { "/p[1]" }
range_end_offset 11 range_end_offset { 11 }
end end
factory :legislation_question, class: "Legislation::Question" do factory :legislation_question, class: "Legislation::Question" do
process factory: :legislation_process process factory: :legislation_process
title "Question text" title { "Question text" }
author factory: :user author factory: :user
end end
@@ -178,55 +178,55 @@ LOREM_IPSUM
factory :legislation_proposal, class: "Legislation::Proposal" do factory :legislation_proposal, class: "Legislation::Proposal" do
sequence(:title) { |n| "Proposal #{n} for a legislation" } sequence(:title) { |n| "Proposal #{n} for a legislation" }
summary "This law should include..." summary { "This law should include..." }
terms_of_service "1" terms_of_service { "1" }
process factory: :legislation_process process factory: :legislation_process
author factory: :user author factory: :user
end end
factory :debate_comment, class: "Comment" do factory :debate_comment, class: "Comment" do
commentable_id "10" commentable_id { "10" }
commentable_type Legislation::Question commentable_type { Legislation::Question }
body "This is a comment" body { "This is a comment" }
user_id "1" user_id { "1" }
cached_votes_down "0" cached_votes_down { "0" }
cached_votes_total "0" cached_votes_total { "0" }
cached_votes_up "0" cached_votes_up { "0" }
confidence_score "0" confidence_score { "0" }
end end
factory :text_comment, class: "Comment" do factory :text_comment, class: "Comment" do
commentable_id "10" commentable_id { "10" }
commentable_type Legislation::Annotation commentable_type { Legislation::Annotation }
body "This is a comment" body { "This is a comment" }
user_id "1" user_id { "1" }
cached_votes_down "0" cached_votes_down { "0" }
cached_votes_total "0" cached_votes_total { "0" }
cached_votes_up "0" cached_votes_up { "0" }
confidence_score "0" confidence_score { "0" }
ancestry nil ancestry { nil }
end end
factory :legislation_people_proposal, class: "Legislation::PeopleProposal" do factory :legislation_people_proposal, class: "Legislation::PeopleProposal" do
sequence(:title) { |n| "People and group #{n} for a legislation" } sequence(:title) { |n| "People and group #{n} for a legislation" }
summary "This law should be implemented by..." summary { "This law should be implemented by..." }
terms_of_service "1" terms_of_service { "1" }
process factory: :legislation_process process factory: :legislation_process
author factory: :user author factory: :user
validated false validated { false }
trait :with_contact_info do trait :with_contact_info do
email "proposal@test.com" email { "proposal@test.com" }
website "https://proposal.io" website { "https://proposal.io" }
phone "666666666" phone { "666666666" }
facebook "facebook.id" facebook { "facebook.id" }
twitter "TwitterId" twitter { "TwitterId" }
youtube "youtubechannelid" youtube { "youtubechannelid" }
instagram "instagramid" instagram { "instagramid" }
end end
trait :validated do trait :validated do
validated true validated { true }
end end
end end
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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