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

Add Rake Task for creating test resources in the DB #254

Merged
merged 2 commits into from
Nov 12, 2023
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ $ cd finder/api
$ bundle exec rails db:create db:migrate db:seed
```

`Users`, `groups`, and test study `sessions` can also be created with the following commands:

```
$ cd finder/api
$ bundle exec rake db:seed:resources
```

### Start App Locally

Run `api` (BE) and `client` (FE) separately.
Expand Down
113 changes: 113 additions & 0 deletions api/db/seeds/resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# frozen_string_literal: true

# Users
user_one = User.create!(
name: 'User One',
email: '[email protected]',
password: 'Test#123',
confirmed_at: DateTime.now,
birth_date: DateTime.parse('2000-01-01'),
bio: 'This is User One\'s bio',
social_networks: {
facebook: 'foo',
instagram: 'bar'
},
career_ids: [1],
subject_ids: [1, 2, 3]
)

user_two = User.create!(
name: 'User Two',
email: '[email protected]',
password: 'Test#123',
confirmed_at: DateTime.now,
birth_date: DateTime.parse('2000-01-01'),
bio: 'This is User Two\'s bio',
social_networks: {
facebook: 'foo',
instagram: 'bar'
},
career_ids: [2],
subject_ids: [1, 2, 3]
)

user_three = User.create!(
name: 'User Three',
email: '[email protected]',
password: 'Test#123',
confirmed_at: DateTime.now,
birth_date: DateTime.parse('2000-01-01'),
bio: 'This is User Three\'s bio',
social_networks: {
facebook: 'foo',
instagram: 'bar'
},
career_ids: [3],
subject_ids: [1, 2, 3]
)

# Groups
group_one = Group.create!(
name: 'Group One',
description: 'This is Group One\'s description',
size: 10,
time_preferences: {
'Friday' => 'None',
'Sunday' => 'Morning'
},
subject_id: 1
)

creator_member_one = group_one.members.create!(
user: user_one,
role: 'admin'
)

group_one.members.create!(
user: user_three,
role: 'participant'
)

group_two = Group.create!(
name: 'Group Two',
description: 'This is Group Two\'s description',
size: 8,
time_preferences: {
'Monday' => 'Morning',
'Wednesday' => 'Night'
},
subject_id: 2
)

creator_member_two = group_two.members.create!(
user: user_two,
role: 'admin'
)

group_two.members.create!(
user: user_three,
role: 'participant'
)

# Sessions
Session.create!(
name: 'Session One',
description: 'This is Session One\'s description',
location: 'Location One',
meeting_link: 'https://meet.example.com/session1',
start_time: DateTime.now + 1.day,
end_time: DateTime.now + 1.day + 2.hours,
group_id: group_one.id,
creator: creator_member_one
)

Session.create!(
name: 'Session Two',
description: 'This is Session Two\'s description',
location: 'Location Two',
meeting_link: 'https://meet.example.com/session2',
start_time: DateTime.now + 2.days,
end_time: DateTime.now + 2.days + 2.5.hours,
group_id: group_two.id,
creator: creator_member_two
)
11 changes: 11 additions & 0 deletions api/lib/tasks/resources.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace :db do
namespace :seed do
Dir[Rails.root.join('db', 'seeds', '*.rb')].each do |filename|
task_name = File.basename(filename, '.rb')
desc "Seed #{task_name}, based on the file with the same name in `db/seeds/*.rb`"
task task_name.to_sym => :environment do
load(filename) if File.exist?(filename)
end
end
end
end