Skip to content
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

Replace jquery_ujs with rails-ujs in frontend and backend #3027

Merged
merged 5 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions backend/app/assets/javascripts/spree/backend.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//= require solidus_admin/bind-polyfill
//= require handlebars
//= require jquery
//= require jquery_ujs
//= require jquery.sticky-kit.min
//= require solidus_admin/select2
//= require solidus_admin/underscore
Expand Down
20 changes: 18 additions & 2 deletions backend/app/assets/javascripts/spree/backend/store_credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@ Spree.ready(function() {
field.defaultValue = field.value;
textDisplay.textContent = field.value;

show_flash('success', data.message);
if (typeof data !== "undefined") {
// we are using jquery_ujs
message = data.message
} else {
// we are using rails-ujs
message = event.detail[0].message
}

show_flash('success', message);
}).on('ajax:error', function(event, xhr, status, error) {
show_flash('error', xhr.responseJSON.message);
if (typeof xhr !== "undefined") {
// we are using jquery_ujs
message = xhr.responseJSON.message
} else {
// we are using rails-ujs
message = event.detail[0].message
}

show_flash('error', message);
});

row.querySelector('.edit-memo').addEventListener('click', function() {
Expand Down
49 changes: 49 additions & 0 deletions backend/spec/features/admin/store_credits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,55 @@
end
end

describe "displaying a store credit details page" do
before do
visit spree.admin_path
click_link "Users"
click_link store_credit.user.email
click_link "Store Credit"
page.find(".sc-table td.actions a.fa-edit").click
end

it "shows the store credit's information" do
within ".content" do
expect(page).to have_content "Credited #{store_credit.display_amount}"
expect(page).to have_content "Created By #{store_credit.created_by.email}"
expect(page).to have_content "Type #{store_credit.category_name}"
expect(page).to have_content 'Store credit history'
end
end

it "lets edit store credit's memo", js: true do
allow_any_instance_of(Spree::Admin::StoreCreditsController)
.to receive(:try_spree_current_user)
.and_return(admin_user)

# When there are no errors
within '.store-credit-memo-row' do
click_button 'Edit'
fill_in 'store_credit_memo', with: 'Lottery Won'
click_button 'Save'
expect(page).to have_content "Memo Lottery Won"
end
expect(page).to have_content "Store Credit has been successfully updated!"

# When there are errors
allow_any_instance_of(Spree::StoreCredit).to receive(:save) { false }
allow_any_instance_of(Spree::StoreCredit)
.to receive_message_chain(:errors, :full_messages)
.and_return(["Memo is not valid"])

within '.store-credit-memo-row' do
find(:css, ".edit-memo").click
fill_in 'store_credit_memo', with: 'Lottery Won Twice'
find(:css, ".save-memo").click
expect(page).to have_content "Memo Lottery Won"
expect(page).not_to have_content "Memo Lottery Won Twice"
end
expect(page).to have_content "Unable to update store credit [\"Memo is not valid\"]"
end
end

describe "updating store credit" do
let(:updated_amount) { "99.0" }
let!(:update_reason) { create(:store_credit_update_reason) }
Expand Down
2 changes: 2 additions & 0 deletions backend/spec/javascripts/spec_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//= require support/chai-jq-0.0.7

//= require_self
//= require jquery
//= require rails-ujs
//= require spree/backend
//= require_tree ./support

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require spree/backend
//= require_tree .
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require spree/frontend
//= require_tree .
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require spree/backend
//= require_tree .
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require spree/frontend
//= require_tree .
3 changes: 1 addition & 2 deletions guides/source/developers/assets/asset-management.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ in this `spree/backend` directory:

```javascript
//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require spree/backend
//= require_tree .
```
Expand Down Expand Up @@ -159,4 +159,3 @@ migrations see the [`install_generator` for

[rails-generators]: http://guides.rubyonrails.org/generators.html
[solidus-static-content-install-generator]: https://github.com/solidusio-contrib/solidus_static_content/blob/master/lib/generators/solidus_static_content/install/install_generator.rb