Skip to content

Commit

Permalink
Merge pull request #254 from wyeworks/juan_arias--rake_task_for_resou…
Browse files Browse the repository at this point in the history
…rces

Add Rake Task for creating test resources in the DB
  • Loading branch information
juanarias93 authored Nov 12, 2023
2 parents f82ff1c + 89745d0 commit 4bb46b9
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
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

0 comments on commit 4bb46b9

Please sign in to comment.