-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
561ee17
commit 46ba198
Showing
11 changed files
with
136 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hotsheet | ||
class << self | ||
def editable_attributes_for(model:) | ||
@editable_attributes_for ||= {} | ||
@editable_attributes_for[model] ||= fetch_editable_attributes(model) | ||
end | ||
|
||
private | ||
|
||
def fetch_editable_attributes(model) | ||
model_config = Hotsheet.configuration.models[model.to_s] | ||
|
||
if model_config&.included_attributes | ||
model_config.included_attributes.map(&:to_s) | ||
elsif model_config&.excluded_attributes | ||
model.column_names - model_config.excluded_attributes.map(&:to_s) | ||
else | ||
model.column_names | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe "Hotsheet" do | ||
describe ".editable_attributes_for" do | ||
subject(:editable_attributes) { Hotsheet.editable_attributes_for(model: Author) } | ||
|
||
before do | ||
Hotsheet.instance_variable_set(:@editable_attributes_for, nil) # reset the memoized editable attributes | ||
end | ||
|
||
context "when included attributes are specified" do | ||
before do | ||
Hotsheet.configure do |config| | ||
config.model :Author do |model| | ||
model.included_attributes = %i[name birthdate] | ||
end | ||
end | ||
end | ||
|
||
it "returns only the included attributes" do | ||
expect(editable_attributes).to eq %w[name birthdate] | ||
end | ||
end | ||
|
||
context "when excluded attributes are specified" do | ||
before do | ||
Hotsheet.configure do |config| | ||
config.model :Author do |model| | ||
model.excluded_attributes = %i[gender created_at updated_at] | ||
end | ||
end | ||
end | ||
|
||
it "returns all attributes except the excluded ones" do | ||
expect(editable_attributes).to eq %w[id name birthdate] | ||
end | ||
end | ||
|
||
context "when included attributes are empty" do | ||
before do | ||
Hotsheet.configure do |config| | ||
config.model :Author do |model| | ||
model.included_attributes = %i[] | ||
end | ||
end | ||
end | ||
|
||
it "returns an empty list" do | ||
expect(editable_attributes).to eq %w[] | ||
end | ||
end | ||
|
||
context "when excluded attributes are empty" do | ||
before do | ||
Hotsheet.configure do |config| | ||
config.model :Author do |model| | ||
model.excluded_attributes = %i[] | ||
end | ||
end | ||
end | ||
|
||
it "returns all attributes" do | ||
expect(editable_attributes).to eq Author.column_names | ||
end | ||
end | ||
|
||
context "when no included or excluded attributes are specified" do | ||
before do | ||
Hotsheet.configure do |config| | ||
config.model :Author | ||
end | ||
end | ||
|
||
it "returns all attributes of the model" do | ||
expect(Hotsheet.configuration.models["Author"]).to be_a Hotsheet::Configuration::ModelConfig | ||
expect(editable_attributes).to eq %w[id name birthdate gender created_at updated_at] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module CapybaraUtils | ||
def wait_for_turbo(timeout = nil) | ||
return unless has_css?(".turbo-progress-bar", visible: true, wait: 1.second) | ||
|
||
has_no_css?(".turbo-progress-bar", wait: timeout.presence || 5.seconds) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters