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

Added has_and_belongs_to_many relation support #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions lib/model/active_record/relation/has_and_belongs_to_many.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Regressor
module Model
module Relation
module HasAndBelongsToMany
def has_and_belongs_to_many_relations
@model.constantize.reflect_on_all_associations(:has_and_belongs_to_many).map(&:name).map do |relation|
"it { is_expected.to have_and_belong_to_many :#{relation} }"
end.join("\n ")
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/model/active_record_model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative 'active_record/util'
require_relative 'active_record/relation/belong_to'
require_relative 'active_record/relation/has_and_belongs_to_many'
require_relative 'active_record/relation/has_one'
require_relative 'active_record/relation/has_many'
require_relative 'active_record/validation/presence'
Expand All @@ -17,6 +18,7 @@ module Model
class ActiveRecordModel
# === Includes ===
include Relation::BelongTo
include Relation::HasAndBelongsToMany
include Relation::HasOne
include Relation::HasMany
include Validation
Expand Down
1 change: 1 addition & 0 deletions lib/templates/model/active_record/model_template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RSpec.describe <%= @model.model %>, regressor: true do

# === Relations ===
<%= @model.belong_to_relations %>
<%= @model.has_and_belongs_to_many_relations %>
<%= @model.has_one_relations %>
<%= @model.has_many_relations %>

Expand Down