Skip to content
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
2 changes: 1 addition & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def set_provider
end

def provider_params
params.expect(provider: [ :name, :provider_type, region_ids: [] ])
params.expect(provider: [ :name, :provider_type, region_ids: [], user_ids: [] ])
end
end
4 changes: 4 additions & 0 deletions app/models/contributor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Contributor < ApplicationRecord
belongs_to :provider
belongs_to :user
end
3 changes: 3 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Provider < ApplicationRecord
has_many :branches
has_many :regions, through: :branches
has_many :contributors
has_many :users, through: :contributors

validates :name, :provider_type, presence: true
validates :name, uniqueness: true
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class User < ApplicationRecord
has_secure_password
has_many :sessions, dependent: :destroy
has_many :contributors
has_many :providers, through: :contributors

normalizes :email, with: ->(e) { e.strip.downcase }

Expand Down
7 changes: 7 additions & 0 deletions app/views/providers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
</div>
</div>

<div class="col-md-4">
<div class="form-group">
<%= form.label :contributors, style: "display: block" %>
<%= form.collection_select :user_ids, User.order(:email), :id, :email, { include_hidden: false }, class: "form-select", multiple: true %>
</div>
</div>

<div class="mt-4">
<div class="col-12 d-flex justify-content-end">
<%= form.submit "Create Provider", class: "btn btn-primary me-1 mb-1" %>
Expand Down
13 changes: 13 additions & 0 deletions app/views/providers/_provider.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@
<% end %>
</ul>
</p>

<p>
<strong>Provider contributors:</strong>
<ul>
<% provider.users.each do |user| %>
<li>
<%= link_to user_path(user) do %>
<%= user.email %>
<% end %>
</li>
<% end %>
</ul>
</p>
</div>
10 changes: 10 additions & 0 deletions db/migrate/20250204141359_create_contributor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateContributor < ActiveRecord::Migration[8.0]
def change
create_table :contributors do |t|
t.belongs_to :provider
t.belongs_to :user

t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions spec/views/providers/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
require "rails_helper"

RSpec.describe "providers/edit", type: :view do
let(:provider) {
Provider.create!(
name: "MyString",
provider_type: "MyString",
)
}
let(:provider) { create(:provider) }

before(:each) do
assign(:provider, provider)
Expand All @@ -17,8 +12,15 @@

assert_select "form[action=?][method=?]", provider_path(provider), "post" do
assert_select "input[name=?]", "provider[name]"

assert_select "input[name=?]", "provider[provider_type]"
end
end

it "renders the contributor form group" do
render

assert_select "form[action=?][method=?]", provider_path(provider), "post" do
assert_select "select[id=?]", "provider_user_ids"
end
end
end
2 changes: 1 addition & 1 deletion spec/views/providers/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
provider_type: "Provider Type",
),
Provider.create!(
name: "Name",
name: "Name1",
provider_type: "Provider Type",
),
],)
Expand Down