messages are an array
This commit is contained in:
parent
c80a003922
commit
256b44ad60
|
@ -8,13 +8,13 @@ module DiscourseDonations
|
|||
|
||||
def create
|
||||
if create_account && (email.nil? || email.empty?)
|
||||
response = {'messages' => 'Please enter your email address'}
|
||||
response = {'messages' => ['Please enter your email address']}
|
||||
elsif create_account && params[:username].nil?
|
||||
response = {'messages' => 'Please enter a username'}
|
||||
response = {'messages' => ['Please enter a username']}
|
||||
else
|
||||
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
||||
response = payment.charge(email, params)
|
||||
response['messages'] = response['outcome']['seller_message']
|
||||
response['messages'] = [response['outcome']['seller_message']]
|
||||
end
|
||||
|
||||
response['rewards'] = []
|
||||
|
|
|
@ -10,7 +10,7 @@ export default Ember.Component.extend({
|
|||
{ value: 20, name: '$20.00'},
|
||||
{ value: 50, name: '$50.00'}
|
||||
],
|
||||
result: null,
|
||||
result: [],
|
||||
amount: null,
|
||||
stripe: null,
|
||||
transactionInProgress: null,
|
||||
|
@ -44,6 +44,10 @@ export default Ember.Component.extend({
|
|||
this.set('transactionInProgress', false);
|
||||
},
|
||||
|
||||
concatMessages(messages) {
|
||||
this.set('result', this.get('result').concat(messages));
|
||||
},
|
||||
|
||||
createUser() {
|
||||
let self = this;
|
||||
ajax('/users/hp', { method: 'get' }).then(data => {
|
||||
|
@ -58,7 +62,7 @@ export default Ember.Component.extend({
|
|||
|
||||
ajax('/users', { data: params, method: 'post' }).then(data => {
|
||||
self.setSuccess();
|
||||
self.set('result', self.get('result') + data.messages);
|
||||
self.concatMessages(data.messages);
|
||||
self.endTranscation();
|
||||
});
|
||||
});
|
||||
|
@ -70,7 +74,7 @@ export default Ember.Component.extend({
|
|||
|
||||
this.get('stripe').createToken(this.get('card')).then(data => {
|
||||
|
||||
self.set('result', '');
|
||||
self.set('result', []);
|
||||
|
||||
if (data.error) {
|
||||
self.set('result', data.error.message);
|
||||
|
@ -88,7 +92,7 @@ export default Ember.Component.extend({
|
|||
|
||||
if(!self.get('paymentSuccess')) {
|
||||
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
||||
self.set('result', data.messages);
|
||||
self.concatMessages(data.messages);
|
||||
|
||||
if(!this.get('create_accounts')) {
|
||||
if(data.status == 'succeeded') { this.setSuccess() };
|
||||
|
@ -105,7 +109,7 @@ export default Ember.Component.extend({
|
|||
});
|
||||
}
|
||||
else if (this.get('create_accounts')) {
|
||||
self.set('result', '');
|
||||
self.set('result', []);
|
||||
self.createUser();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,9 +60,11 @@
|
|||
{{#if transactionInProgress}}
|
||||
{{loading-spinner size="small"}}
|
||||
{{/if}}
|
||||
{{#if result}}
|
||||
<p>{{{result}}}</p>
|
||||
{{/if}}
|
||||
|
||||
{{#each result as |message|}}
|
||||
<p>{{{message}}}</p>
|
||||
{{/each}}
|
||||
|
||||
{{#if success}}
|
||||
<p>{{i18n 'discourse_donations.messages.success'}}</p>
|
||||
{{/if}}
|
||||
|
|
|
@ -14,32 +14,32 @@ module DiscourseDonations
|
|||
|
||||
it 'responds ok for anonymous users' do
|
||||
post :create, { email: 'foobar@example.com' }
|
||||
expect(body['messages']).to eq(body['outcome']['seller_message'])
|
||||
expect(body['messages']).to include(body['outcome']['seller_message'])
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'responds ok when the email is empty' do
|
||||
post :create, { create_account: 'true', email: '' }
|
||||
expect(body['messages']).to eq('Please enter your email address')
|
||||
expect(body['messages']).to include('Please enter your email address')
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'responds ok when the email is empty' do
|
||||
post :create, { create_account: 'true' }
|
||||
expect(body['messages']).to eq('Please enter your email address')
|
||||
expect(body['messages']).to include('Please enter your email address')
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'expects a username if accounts are being created' do
|
||||
post :create, { email: 'zipitydoodah@example.com', create_account: 'true' }
|
||||
expect(body['messages']).to eq('Please enter a username')
|
||||
expect(body['messages']).to include('Please enter a username')
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'does not expect a username or email if accounts are not being created' do
|
||||
current_user = log_in(:coding_horror)
|
||||
post :create, { create_account: 'false' }
|
||||
expect(body['messages']).to eq('Payment complete.')
|
||||
expect(body['messages']).to include('Payment complete.')
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue