60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/spec/dummy/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blocknotes/activeadmin_select_many/9e367faf4d987560383b2ffa5614607a444f8f0b/spec/dummy/public/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/spec/dummy/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blocknotes/activeadmin_select_many/9e367faf4d987560383b2ffa5614607a444f8f0b/spec/dummy/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/spec/dummy/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blocknotes/activeadmin_select_many/9e367faf4d987560383b2ffa5614607a444f8f0b/spec/dummy/public/favicon.ico
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'spec_helper'
4 |
5 | ENV['RAILS_ENV'] = 'test'
6 |
7 | require File.expand_path('dummy/config/environment.rb', __dir__)
8 |
9 | abort('The Rails environment is running in production mode!') if Rails.env.production?
10 |
11 | require 'rspec/rails'
12 | require 'capybara/rails'
13 |
14 | Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f }
15 |
16 | require 'simplecov'
17 | SimpleCov.start :rails do
18 | filters.clear
19 | add_filter %r{^/spec/}
20 | end
21 |
22 | # Force deprecations to raise an exception.
23 | ActiveSupport::Deprecation.behavior = :raise
24 |
25 | # Checks for pending migrations and applies them before tests are run.
26 | # If you are not using ActiveRecord, you can remove these lines.
27 | begin
28 | ActiveRecord::Migration.maintain_test_schema!
29 | rescue ActiveRecord::PendingMigrationError => e
30 | puts e.to_s.strip
31 | exit 1
32 | end
33 |
34 | RSpec.configure do |config|
35 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
36 | config.infer_spec_type_from_file_location!
37 | config.filter_rails_from_backtrace!
38 |
39 | config.use_transactional_fixtures = true
40 | config.use_instantiated_fixtures = false
41 | config.render_views = false
42 | end
43 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.configure do |config|
4 | config.disable_monkey_patching!
5 | config.filter_run focus: true
6 | config.filter_run_excluding changes_filesystem: true
7 | config.run_all_when_everything_filtered = true
8 | config.color = true
9 | config.order = :random
10 | config.example_status_persistence_file_path = '.rspec_failures'
11 |
12 | config.shared_context_metadata_behavior = :apply_to_host_groups
13 |
14 | config.expect_with :rspec do |expectations|
15 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
16 | end
17 | config.mock_with :rspec do |mocks|
18 | mocks.verify_partial_doubles = true
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/spec/support/capybara.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Capybara.server = :puma
4 |
--------------------------------------------------------------------------------
/spec/support/drivers.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.configure do |config|
4 | config.before(:each, type: :system) do
5 | driven_by(:selenium_chrome_headless)
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/spec/system/select_many_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe 'Select many', type: :system do # rubocop:disable Metrics/BlockLength
4 | let(:author) { Author.create!(email: 'some_email@example.com', name: 'John Doe', age: 30) }
5 | let(:post) { Post.create!(title: 'Test', author: author) }
6 | let(:tags) do
7 | 3.times.map do |i|
8 | Tag.create!(name: "A tag #{i}")
9 | end
10 | end
11 |
12 | before do
13 | post.tags << tags.last
14 | end
15 |
16 | after do
17 | post.destroy
18 | author.destroy
19 | tags.each(&:destroy)
20 | end
21 |
22 | context 'with a select_many input' do
23 | let(:source_select) { '#post_tags_input select[data-select="src"]' }
24 | let(:destination_select) { '#post_tags_input select[data-select="dst"]' }
25 |
26 | it 'includes the input selects' do
27 | visit "/admin/posts/#{post.id}/edit"
28 |
29 | expect(page).to have_css(source_select)
30 | expect(page).to have_css(destination_select)
31 | src_options = find_all("#{source_select} option").map(&:text)
32 | expect(src_options).to match_array(Tag.pluck(:name) - post.tags.pluck(:name))
33 | dst_option = find("#{destination_select} option", match: :first)
34 | expect([dst_option.value, dst_option.text]).to eq [post.tags.first.id.to_s, post.tags.first.name]
35 | end
36 |
37 | it 'updates the entity association' do
38 | visit "/admin/posts/#{post.id}/edit"
39 |
40 | find(destination_select).click
41 | find("#{destination_select} option", match: :first).double_click
42 | expect(find_all("#{destination_select} option")).to be_empty
43 | find(source_select).click
44 | first_option = find("#{source_select} option", match: :first)
45 | text = first_option.text
46 | first_option.double_click
47 | expect(find_all("#{destination_select} option").map(&:text)).to eq [text]
48 |
49 | find('[type="submit"]').click
50 | expect(page).to have_content('was successfully updated')
51 | expect(post.reload.tags.pluck(:name)).to eq [text]
52 | end
53 | end
54 | end
55 |
--------------------------------------------------------------------------------
/spec/system/select_one_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe 'Select one', type: :system do # rubocop:disable Metrics/BlockLength
4 | let(:authors) do
5 | 3.times.map do |i|
6 | Author.create!(email: "some_email_#{i}@example.com", name: "John #{i}", age: 30 + i * 3)
7 | end
8 | end
9 | let(:post) { Post.create!(title: 'Test', author: authors.first) }
10 |
11 | before do
12 | post
13 | end
14 |
15 | after do
16 | post.destroy
17 | authors.each(&:destroy)
18 | end
19 |
20 | context 'with a select_one input' do
21 | let(:search_select) { '#post_author_input .search-select' }
22 |
23 | it 'includes the text search field and the input select' do
24 | visit "/admin/posts/#{post.id}/edit"
25 |
26 | expect(page).to have_css(search_select)
27 | expect(page).to have_select('post[author_id]', selected: authors.first.name)
28 | end
29 |
30 | it 'updates the entity association' do
31 | visit "/admin/posts/#{post.id}/edit"
32 |
33 | author_name = authors.last.name
34 | find_field('post[author_id]').select(author_name)
35 | find('[type="submit"]').click
36 | expect(page).to have_content('was successfully updated')
37 | expect(post.reload.author.name).to eq(author_name)
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------