-
Notifications
You must be signed in to change notification settings - Fork 3
First Homework #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
df93bdb
1f868dc
5ed3c6e
2af60d2
48562ef
4f58cd5
cd4a631
5fbfa80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --require spec_helper |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class Comment < ApplicationRecord | ||
| belongs_to :episode | ||
| belongs_to :user | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| class Like < ApplicationRecord | ||
| belongs_to :episode | ||
| belongs_to :user | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class PlayStat < ApplicationRecord | ||
| belongs_to :episode | ||
| belongs_to :user | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class CreateComments < ActiveRecord::Migration[8.0] | ||
| def change | ||
| create_table :comments do |t| | ||
| t.references :episode, null: false, foreign_key: true | ||
| t.references :user, null: false, foreign_key: true | ||
| t.text :text | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class CreatePlayStats < ActiveRecord::Migration[8.0] | ||
| def change | ||
| create_table :play_stats do |t| | ||
| t.references :episode, null: false, foreign_key: true | ||
| t.references :user, null: false, foreign_key: true | ||
| t.integer :position | ||
| t.boolean :is_finished, default: false | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| FactoryBot.define do | ||
| factory :account do | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| FactoryBot.define do | ||
| factory :episode do | ||
| title { 'Episode One' } | ||
|
|
||
| trait :with_podcast do | ||
| association :podcast, factory: :podcast | ||
| end | ||
|
|
||
| trait :with_archived_podcast do | ||
| association :podcast, factory: :podcast_archived | ||
| end | ||
|
|
||
| trait :with_status_published do | ||
| status { 'published' } | ||
| end | ||
|
|
||
| trait :with_status_draft do | ||
| status { 'draft' } | ||
| end | ||
|
|
||
| trait :with_status_unpublished do | ||
| status { 'unpublished' } | ||
| end | ||
| end | ||
|
|
||
| factory :episode_with_podcast, parent: :episode, traits: [:with_podcast] | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FactoryBot.define do | ||
| factory :play_stat do | ||
| association :episode, factory: :episode_with_podcast | ||
| association :user, factory: :user | ||
| position { 0 } | ||
| is_finished { false } | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| FactoryBot.define do | ||
| factory :podcast do | ||
| status { 'new' } | ||
| title { 'New title' } | ||
| association :author, factory: :author | ||
|
|
||
| trait :with_archived_status do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. с одной стороны, ты аккуратно сделал через trait, но лучше использовать этот механизм для более сложных переиспользуемых случаев. Один атрибут лучше выставлять прямо в тесте передавая такие атрибуты в фабрику |
||
| status { 'archived' } | ||
| end | ||
|
|
||
| trait :with_nil_title do | ||
| title { nil } | ||
| end | ||
|
|
||
| trait :with_empty_title do | ||
| title { '' } | ||
| end | ||
|
|
||
| trait :without_author do | ||
| author { nil } | ||
| end | ||
|
|
||
| trait :with_author_without_account do | ||
| association :author, factory: :author_without_account | ||
| end | ||
|
|
||
| trait :with_blocked_author do | ||
| association :author, factory: :author_blocked | ||
| end | ||
| end | ||
|
|
||
| factory :podcast_archived, parent: :podcast, traits: [:with_archived_status] | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| FactoryBot.define do | ||
| factory :user, aliases: [:author, :subscriber, :no_subscriber] do | ||
| name { "John Marston" } | ||
| association :account, factory: :account | ||
|
|
||
| trait :blocked do | ||
| blocked { true } | ||
| end | ||
|
|
||
| trait :without_account do | ||
| account { nil } | ||
| end | ||
| end | ||
|
|
||
| factory :author_blocked, parent: :user, traits: [:blocked] | ||
| factory :author_without_account, parent: :user, traits: [:without_account] | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
супер, что нашел эту конструкцию