adds hound_bot's and zmagos suggestions

This commit is contained in:
Toni Dezman 2017-09-07 13:40:53 +02:00
parent b7bed5b5fe
commit 67d617deb5
3 changed files with 37 additions and 34 deletions

View file

@ -58,11 +58,12 @@ module ClientApi
user.time_zone = params['timezone']
timezone = if user.save
user.time_zone
else
user.reload.time_zone
errors[:timezone_errors] << 'You need to select valid TimeZone.'
end
user.time_zone
else
msg = 'You need to select valid TimeZone.'
user.reload.time_zone
errors[:timezone_errors] << msg
end
respond_to do |format|
format.json { render json: { timezone: timezone, errors: errors}}
@ -77,16 +78,17 @@ module ClientApi
if user.valid_password? params['passwrd']
user.email = params['email']
saved_email = if user.save
user.email
else
user.reload.email
end
user.email
else
user.reload.email
end
else
errors[:current_password_email_field] << 'Wrong password.'
end
respond_to do |format|
format.json { render json: { email: saved_email || current_email, errors: errors } }
resp = { email: saved_email || current_email, errors: errors }
format.json { render json: resp }
end
end
@ -94,24 +96,25 @@ module ClientApi
user = current_user
user.name = params['fullName']
saved_name = if user.save
user.name
else
user.reload.name
end
user.name
else
user.reload.name
end
respond_to do |format|
format.json { render json: { fullName: saved_name, errors: user.errors.messages } }
resp = { fullName: saved_name, errors: user.errors.messages }
format.json { render json: resp }
end
end
def change_initials
user = current_user
user.initials = params['initials']
saved_initials = if user.save
user.initials
else
user.reload.initials
end
saved_initials = if user.save
user.initials
else
user.reload.initials
end
respond_to do |format|
format.json { render json: { initials: saved_initials } }

View file

@ -23,7 +23,7 @@ class NotificationsSwitchGroup extends Component {
super(props);
this.state = {
isSciNoteSwitchOn: false,
isSwitchOn: false,
isEmailSwitchOn: false
};
@ -36,7 +36,7 @@ class NotificationsSwitchGroup extends Component {
switch (this.props.type) {
case ASSIGNMENT_NOTIFICATION:
this.setState({
isSciNoteSwitchOn: this.props.assignmentsNotification,
isSwitchOn: this.props.assignmentsNotification,
isEmailSwitchOn: this.props.assignmentsNotificationEmail,
sciNoteDispatch: state =>
this.props.changeAssignmentsNotification(state),
@ -46,7 +46,7 @@ class NotificationsSwitchGroup extends Component {
break;
case RECENT_NOTIFICATION:
this.setState({
isSciNoteSwitchOn: this.props.recentNotification,
isSwitchOn: this.props.recentNotification,
isEmailSwitchOn: this.props.recentNotificationEmail,
sciNoteDispatch: state => this.props.changeRecentNotification(state),
emailDispatch: state =>
@ -55,7 +55,7 @@ class NotificationsSwitchGroup extends Component {
break;
case SYSTEM_NOTIFICATION:
this.setState({
isSciNoteSwitchOn: true,
isSwitchOn: true,
isEmailSwitchOn: this.props.systemMessageNotificationEmail,
sciNoteDispatch: state => `${state}: Do Nothing`,
emailDispatch: state =>
@ -64,19 +64,19 @@ class NotificationsSwitchGroup extends Component {
break;
default:
this.setState({
isSciNoteSwitchOn: false,
isSwitchOn: false,
isEmailSwitchOn: false
});
}
}
toggleFirstSwitch() {
if (this.state.isSciNoteSwitchOn) {
this.setState({ isSciNoteSwitchOn: false, isEmailSwitchOn: false });
if (this.state.isSwitchOn) {
this.setState({ isSwitchOn: false, isEmailSwitchOn: false });
this.state.sciNoteDispatch(false);
this.state.emailDispatch(false);
} else {
this.setState({ isSciNoteSwitchOn: true });
this.setState({ isSwitchOn: true });
this.state.sciNoteDispatch(true);
}
}
@ -104,7 +104,7 @@ class NotificationsSwitchGroup extends Component {
<div>
<NotificationsSwitch
title="settings_page.show_in_scinote"
isSwitchOn={this.state.isSciNoteSwitchOn}
isSwitchOn={this.state.isSwitchOn}
toggleSwitch={this.toggleFirstSwitch}
isDisabled={this.isSwitchDisabled()}
/>
@ -112,7 +112,7 @@ class NotificationsSwitchGroup extends Component {
title="settings_page.notify_me_via_email"
isSwitchOn={this.state.isEmailSwitchOn}
toggleSwitch={this.toggleSecondSwitch}
isDisabled={!this.state.isSciNoteSwitchOn}
isDisabled={!this.state.isSwitchOn}
/>
</div>
);

View file

@ -46,28 +46,28 @@ describe ClientApi::Users::UsersController, type: :controller do
it 'responds successfully' do
user = User.first
expect(user.time_zone).to eq('UTC')
post :change_timezone, params: { timezone: 'Pacific/Fiji'}, format: :json
post :change_timezone, params: { timezone: 'Pacific/Fiji' }, format: :json
expect(response).to have_http_status(:ok)
end
it 'changes timezone' do
user = User.first
expect(user.time_zone).to eq('UTC')
post :change_timezone, params: { timezone: 'Pacific/Fiji'}, format: :json
post :change_timezone, params: { timezone: 'Pacific/Fiji' }, format: :json
expect(user.reload.time_zone).to eq('Pacific/Fiji')
end
end
describe 'POST change_initials' do
it 'responds successfully' do
post :change_initials, params: { initials: 'TD'}, format: :json
post :change_initials, params: { initials: 'TD' }, format: :json
expect(response).to have_http_status(:ok)
end
it 'responds successfully' do
user = User.first
expect(user.initials).not_to eq('TD')
post :change_initials, params: { initials: 'TD'}, format: :json
post :change_initials, params: { initials: 'TD' }, format: :json
expect(user.reload.initials).to eq('TD')
end
end