forked from rubyforgood/casa
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Issue#2698 persist column visibility state stage 3 completes issue #3
Open
GALTdea
wants to merge
4
commits into
issue#2698_persist_column_visibility_state_stage_2_add_table_state_to_preference_sets_rake_task
Choose a base branch
from
issue#2698_persist_column_visibility_state_stage_3_completes_issue
base: issue#2698_persist_column_visibility_state_stage_2_add_table_state_to_preference_sets_rake_task
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
64ecc16
Add preference_sets controller and table_state table_state_update a…
GALTdea 58985a4
Add new routes for preference_sets controller actions
GALTdea d098c94
Add service object preference_set_table_state and it's test
GALTdea bd76d7b
Add VolunteersTable options to allow data_state persistence
GALTdea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class PreferenceSetsController < ApplicationController | ||
before_action :skip_authorization, :set_table_name | ||
def table_state | ||
render json: PreferenceSetTableStateService.new(user_id: current_user.id).table_state( | ||
table_name: @table_name | ||
) | ||
end | ||
|
||
def table_state_update | ||
render json: PreferenceSetTableStateService.new(user_id: current_user.id).update!( | ||
table_state: params["table_state"], | ||
table_name: @table_name | ||
) | ||
|
||
rescue PreferenceSetTableStateService::TableStateUpdateFailed | ||
render json: {error: "Failed to update table state for '#{@table_name}'" } | ||
end | ||
|
||
|
||
private | ||
def set_table_name | ||
@table_name = params[:table_name] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class PreferenceSetDecorator < ApplicationDecorator | ||
delegate_all | ||
|
||
# Define presentation-specific methods here. Helpers are accessed through | ||
# `helpers` (aka `h`). You can override attributes, for example: | ||
# | ||
# def created_at | ||
# helpers.content_tag :span, class: 'time' do | ||
# object.created_at.strftime("%a %m/%d/%y") | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PreferenceSetsHelper | ||
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,25 @@ | ||
class PreferenceSetTableStateService | ||
class TableStateUpdateFailed < StandardError; end | ||
def initialize(user_id:) | ||
@user_id = user_id | ||
end | ||
|
||
def table_state(table_name:) | ||
preference_set.table_state[table_name] | ||
end | ||
|
||
def update!(table_name:, table_state:) | ||
preference_set.table_state[table_name] = table_state | ||
preference_set.save! | ||
|
||
rescue StandardError | ||
raise TableStateUpdateFailed, "Failed to update table state for '#{table_name}'" | ||
end | ||
|
||
private | ||
attr_reader :user_id | ||
def preference_set | ||
@preference_set ||= PreferenceSet.find_by!(user_id: user_id) | ||
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,4 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe PreferenceSetDecorator do | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the PreferenceSetsHelper. For example: | ||
# | ||
# describe PreferenceSetsHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe PreferenceSetsHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "PreferenceSets", type: :request do | ||
describe "GET /index" do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe PreferenceSetTableStateService do | ||
subject { described_class.new(user_id: user.id) } | ||
|
||
let!(:user) { create(:user) } | ||
let(:preference_set) { user.preference_set } | ||
let!(:table_state) { { "volunteers_table" => { "columns" => [{"visible" => true}] }} } | ||
let(:table_state2) { { "columns" => [{"visible" => false}] }} | ||
let(:table_name) { "volunteers_table" } | ||
|
||
describe '#update!' do | ||
context 'when the update is successful' do | ||
it 'updates the table state' do | ||
expect { | ||
subject.update!(table_state: table_state2, table_name: table_name) | ||
}.to change { | ||
preference_set.reload.table_state | ||
}.from({}).to({ table_name => table_state2 }) | ||
end | ||
end | ||
|
||
context 'when the update fails' do | ||
before do | ||
allow_any_instance_of(PreferenceSet).to receive(:save!).and_raise(ActiveRecord::RecordNotSaved) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { | ||
subject.update!(table_state: table_state2, table_name: table_name) | ||
}.to raise_error(PreferenceSetTableStateService::TableStateUpdateFailed, "Failed to update table state for '#{table_name}'") | ||
end | ||
end | ||
end | ||
|
||
describe '#table_state' do | ||
context 'when the preference set exists' do | ||
before do | ||
table_state = { "columns" => [{"visible" => true}]} | ||
user.preference_set.table_state["volunteers_table"] = table_state | ||
user.preference_set.save! | ||
end | ||
|
||
it 'returns the table state' do | ||
binding.pry | ||
expect(subject.table_state(table_name: "volunteers_table")).to eq(table_state["volunteers_table"]) | ||
end | ||
end | ||
|
||
context 'when there is no data for that table name' do | ||
before do | ||
preference_set.table_state = {} | ||
preference_set.save | ||
end | ||
|
||
it 'returns nil' do | ||
expect(subject.table_state(table_name: table_name)).to eq(nil) | ||
end | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an empty line at the end.