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

View file

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

View file

@ -46,28 +46,28 @@ describe ClientApi::Users::UsersController, type: :controller do
it 'responds successfully' do it 'responds successfully' do
user = User.first user = User.first
expect(user.time_zone).to eq('UTC') 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) expect(response).to have_http_status(:ok)
end end
it 'changes timezone' do it 'changes timezone' do
user = User.first user = User.first
expect(user.time_zone).to eq('UTC') 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') expect(user.reload.time_zone).to eq('Pacific/Fiji')
end end
end end
describe 'POST change_initials' do describe 'POST change_initials' do
it 'responds successfully' 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) expect(response).to have_http_status(:ok)
end end
it 'responds successfully' do it 'responds successfully' do
user = User.first user = User.first
expect(user.initials).not_to eq('TD') 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') expect(user.reload.initials).to eq('TD')
end end
end end