Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamic attributes in factories #1484

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/alchemy/test_support/factories/attachment_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

FactoryBot.define do
factory :alchemy_attachment, class: 'Alchemy::Attachment' do
file File.new(Alchemy::Engine.root.join('lib', 'alchemy', 'test_support', 'fixtures', 'image.png'))
name 'image'
file_name 'image.png'
file do
File.new(Alchemy::Engine.root.join('lib', 'alchemy', 'test_support', 'fixtures', 'image.png'))
end
name { 'image' }
file_name { 'image.png' }
end
end
2 changes: 1 addition & 1 deletion lib/alchemy/test_support/factories/cell_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
FactoryBot.define do
factory :alchemy_cell, class: 'Alchemy::Cell' do
page { Alchemy::Page.find_by(language_root: true) || FactoryBot.create(:alchemy_page, :language_root) }
name "a_cell"
name { "a_cell" }
end
end
8 changes: 4 additions & 4 deletions lib/alchemy/test_support/factories/content_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

FactoryBot.define do
factory :alchemy_content, class: 'Alchemy::Content' do
name "text"
essence_type "Alchemy::EssenceText"
name { "text" }
essence_type { "Alchemy::EssenceText" }
association :essence, factory: :alchemy_essence_text
association :element, factory: :alchemy_element

trait :essence_file do
essence_type "Alchemy::EssenceFile"
essence_type { "Alchemy::EssenceFile" }
association :essence, factory: :alchemy_essence_file
end

trait :essence_picture do
essence_type "Alchemy::EssencePicture"
essence_type { "Alchemy::EssencePicture" }
association :essence, factory: :alchemy_essence_picture
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/alchemy/test_support/factories/dummy_user_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
FactoryBot.define do
factory :alchemy_dummy_user, class: 'DummyUser' do
sequence(:email) { |n| "john.#{n}@doe.com" }
password 's3cr3t'
alchemy_roles ['member']
password { 's3cr3t' }
alchemy_roles { ['member'] }

trait :as_admin do
alchemy_roles ['admin']
alchemy_roles { ['admin'] }
end

trait :as_author do
alchemy_roles ['author']
alchemy_roles { ['author'] }
end

trait :as_editor do
alchemy_roles ['editor']
alchemy_roles { ['editor'] }
end
end
end
14 changes: 7 additions & 7 deletions lib/alchemy/test_support/factories/element_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

FactoryBot.define do
factory :alchemy_element, class: 'Alchemy::Element' do
name 'article'
create_contents_after_create false
name { 'article' }
create_contents_after_create { false }
association :page, factory: :alchemy_page

trait :unique do
unique true
name 'header'
unique { true }
name { 'header' }
end

trait :with_nestable_elements do
name 'slider'
name { 'slider' }
end

trait :nested do
association :parent_element, factory: :alchemy_element, name: 'slider'
name 'slide'
name { 'slide' }
end

trait :with_contents do
create_contents_after_create true
create_contents_after_create { true }
end
end
end
2 changes: 1 addition & 1 deletion lib/alchemy/test_support/factories/essence_text_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

FactoryBot.define do
factory :alchemy_essence_text, class: 'Alchemy::EssenceText' do
body 'This is a headline'
body { 'This is a headline' }
end
end
26 changes: 13 additions & 13 deletions lib/alchemy/test_support/factories/language_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@

FactoryBot.define do
factory :alchemy_language, class: 'Alchemy::Language' do
name 'Deutsch'
code 'de'
default true
frontpage_name 'Intro'
name { 'Deutsch' }
code { 'de' }
default { true }
frontpage_name { 'Intro' }
page_layout { Alchemy::Config.get(:default_language)['page_layout'] }
public true
public { true }
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
site { Alchemy::Site.default }

trait :klingon do
name 'Klingon'
code 'kl'
frontpage_name 'Tuq'
default false
name { 'Klingon' }
code { 'kl' }
frontpage_name { 'Tuq' }
default { false }
end

trait :english do
name 'English'
code 'en'
frontpage_name 'Intro'
default false
name { 'English' }
code { 'en' }
frontpage_name { 'Intro' }
default { false }
end
end
end
32 changes: 16 additions & 16 deletions lib/alchemy/test_support/factories/page_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
factory :alchemy_page, class: 'Alchemy::Page' do
language { Alchemy::Language.default || FactoryBot.create(:alchemy_language) }
sequence(:name) { |n| "A Page #{n}" }
page_layout "standard"
page_layout { "standard" }

parent_id do
(Alchemy::Page.find_by(language_root: true) ||
Expand All @@ -14,19 +14,19 @@

# This speeds up creating of pages dramatically.
# Pass do_not_autogenerate: false to generate elements
do_not_autogenerate true
do_not_autogenerate { true }

trait :root do
name 'Root'
language nil
parent_id nil
page_layout nil
name { 'Root' }
language { nil }
parent_id { nil }
page_layout { nil }
end

trait :language_root do
name 'Startseite'
name { 'Startseite' }
page_layout { language.page_layout }
language_root true
language_root { true }
public_on { Time.current }
parent_id { Alchemy::Page.root.id }
end
Expand All @@ -37,22 +37,22 @@
end

trait :system do
name "Systempage"
name { "Systempage" }
parent_id { Alchemy::Page.root.id }
language_root false
page_layout nil
language nil
language_root { false }
page_layout { nil }
language { nil }
end

trait :layoutpage do
name "Footer"
name { "Footer" }
parent_id { Alchemy::Page.find_or_create_layout_root_for(Alchemy::Language.current.id).id }
page_layout "footer"
page_layout { "footer" }
end

trait :restricted do
name "Restricted page"
restricted true
name { "Restricted page" }
restricted { true }
end

trait :locked do
Expand Down
10 changes: 6 additions & 4 deletions lib/alchemy/test_support/factories/picture_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

FactoryBot.define do
factory :alchemy_picture, class: 'Alchemy::Picture' do
image_file File.new(Alchemy::Engine.root.join('lib', 'alchemy', 'test_support', 'fixtures', 'image.png'))
name 'image'
image_file_name 'image.png'
upload_hash Time.current.hash
image_file do
File.new(Alchemy::Engine.root.join('lib', 'alchemy', 'test_support', 'fixtures', 'image.png'))
end
name { 'image' }
image_file_name { 'image.png' }
upload_hash { Time.current.hash }
end
end
12 changes: 6 additions & 6 deletions lib/alchemy/test_support/factories/site_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

FactoryBot.define do
factory :alchemy_site, class: 'Alchemy::Site' do
name 'A Site'
host 'domain.com'
name { 'A Site' }
host { 'domain.com' }

trait :default do
public true
name Alchemy::Config.get(:default_site)['name']
host Alchemy::Config.get(:default_site)['host']
public { true }
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
name { Alchemy::Config.get(:default_site)['name'] }
host { Alchemy::Config.get(:default_site)['host'] }
end

trait :public do
public true
public { true }
end
end
end
22 changes: 11 additions & 11 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

FactoryBot.define do
factory :event do
name 'My Event'
hidden_name 'not shown'
name { 'My Event' }
hidden_name { 'not shown' }
location
starts_at Time.local(2012, 03, 02, 8, 15)
ends_at Time.local(2012, 03, 02, 19, 30)
lunch_starts_at Time.local(2012, 03, 02, 12, 15)
lunch_ends_at Time.local(2012, 03, 02, 13, 45)
description "something\nfancy"
published false
entrance_fee 12.3
starts_at { Time.local(2012, 03, 02, 8, 15) }
ends_at { Time.local(2012, 03, 02, 19, 30) }
lunch_starts_at { Time.local(2012, 03, 02, 12, 15) }
lunch_ends_at { Time.local(2012, 03, 02, 13, 45) }
description { "something\nfancy" }
published { false }
entrance_fee { 12.3 }
end

factory :location do
name 'Awesome Lodge'
name { 'Awesome Lodge' }
end

factory :series do
name 'My Series'
name { 'My Series' }
end
end