museum 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +18 -15
  5. data/README.md +3 -1
  6. data/Rakefile +10 -1
  7. data/VERSION +1 -1
  8. data/app/controllers/museum/cases_controller.rb +9 -17
  9. data/app/models/museum/case.rb +6 -3
  10. data/app/models/museum/case_detail.rb +1 -1
  11. data/app/models/museum/loupe.rb +1 -1
  12. data/app/views/application/404.html.haml +2 -0
  13. data/lib/museum.rb +7 -6
  14. data/museum.gemspec +70 -39
  15. data/spec/controllers/cases_controller_spec.rb +12 -14
  16. data/spec/dummy/.rspec +1 -0
  17. data/spec/dummy/Rakefile +8 -1
  18. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  19. data/spec/dummy/app/models/application_record.rb +3 -0
  20. data/spec/dummy/bin/rails +1 -1
  21. data/spec/dummy/bin/setup +34 -0
  22. data/spec/dummy/bin/update +29 -0
  23. data/spec/dummy/config/application.rb +4 -14
  24. data/spec/dummy/config/boot.rb +3 -3
  25. data/spec/dummy/config/cable.yml +9 -0
  26. data/spec/dummy/config/environment.rb +2 -2
  27. data/spec/dummy/config/environments/development.rb +31 -6
  28. data/spec/dummy/config/environments/production.rb +37 -31
  29. data/spec/dummy/config/environments/test.rb +11 -5
  30. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  31. data/spec/dummy/config/initializers/assets.rb +11 -0
  32. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  34. data/spec/dummy/config/initializers/new_framework_defaults.rb +23 -0
  35. data/spec/dummy/config/initializers/session_store.rb +1 -1
  36. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  37. data/spec/dummy/config/locales/en.yml +23 -0
  38. data/spec/dummy/config/puma.rb +47 -0
  39. data/spec/dummy/config/routes.rb +1 -56
  40. data/spec/dummy/config/secrets.yml +22 -0
  41. data/spec/dummy/config/spring.rb +6 -0
  42. data/spec/dummy/db/development.sqlite3 +0 -0
  43. data/spec/dummy/db/schema.rb +3 -3
  44. data/spec/dummy/db/seeds/cases.seeds.rb +24 -0
  45. data/spec/dummy/db/seeds/loupes.seeds.rb +15 -0
  46. data/spec/dummy/db/seeds.rb +0 -1
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/features/cases_spec.rb +29 -0
  49. data/spec/helpers/cases_helper_spec.rb +1 -1
  50. data/spec/models/case_detail_spec.rb +33 -29
  51. data/spec/models/case_spec.rb +5 -5
  52. data/spec/models/loupe_spec.rb +1 -1
  53. data/spec/museum_spec.rb +1 -1
  54. data/spec/rails_helper.rb +88 -0
  55. data/spec/routing/engine_routes_spec.rb +1 -1
  56. data/spec/spec_helper.rb +79 -59
  57. data/spec/support/case_support.rb +5 -5
  58. data/spec/support/controller_behaviors.rb +116 -0
  59. data/spec/support/loupe_support.rb +2 -2
  60. metadata +140 -32
  61. data/coverage/.last_run.json +0 -5
  62. data/coverage/.resultset.json +0 -548
  63. data/coverage/.resultset.json.lock +0 -0
  64. data/db/seeds/museum_cases.yml +0 -15
  65. data/db/seeds/museum_loupes.yml +0 -13
  66. data/db/seeds.rb +0 -7
  67. data/spec/dummy/coverage/.last_run.json +0 -5
  68. data/spec/dummy/coverage/.resultset.json +0 -114
  69. data/spec/views/cases/index.html.haml_spec.rb +0 -18
  70. data/spec/views/cases/show.html.haml_spec.rb +0 -18
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe Museum::Case do
4
4
  include_context 'loupe support'
@@ -8,16 +8,16 @@ describe Museum::Case do
8
8
  it { should have_many(:case_details) }
9
9
 
10
10
  describe '#freshen_if_expired' do
11
- subject { expired_package.freshen_if_expired.updated_at.to_datetime }
12
- it { should be > (Time.now - Museum.configuration.refresh_interval).to_datetime}
11
+ subject { expired_package.freshen_if_expired }
12
+ its(:updated_at) { should be > (Time.now - Museum.configuration.refresh_interval) }
13
13
  end
14
14
 
15
15
  describe '#expired?' do
16
- context 'on an expired package' do
16
+ describe 'on an expired package' do
17
17
  subject { expired_package.expired? }
18
18
  it { should be true }
19
19
  end
20
- context 'on a fresh package' do
20
+ describe 'on a fresh package' do
21
21
  subject { fresh_package.expired? }
22
22
  it { should be false }
23
23
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe Museum::Loupe do
4
4
  include_context 'loupe support'
data/spec/museum_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe "Museum" do
4
4
  it 'should return correct version string' do
@@ -0,0 +1,88 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
5
+ ENV['RAILS_ENV'] ||= 'test'
6
+ require File.expand_path('../dummy/config/environment', __FILE__)
7
+ # Prevent database truncation if the environment is production
8
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
9
+ require 'spec_helper'
10
+ require 'rspec/rails'
11
+ # Add additional requires below this line. Rails is not loaded until this point!
12
+ require 'shoulda/matchers'
13
+ require 'rspec/its'
14
+ require 'factory_girl_rails'
15
+ require 'database_cleaner'
16
+ require 'rake'
17
+
18
+ # Requires supporting ruby files with custom matchers and macros, etc, in
19
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
20
+ # run as spec files by default. This means that files in spec/support that end
21
+ # in _spec.rb will both be required and run as specs, causing the specs to be
22
+ # run twice. It is recommended that you do not name files matching this glob to
23
+ # end with _spec.rb. You can configure this pattern with the --pattern
24
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
25
+ #
26
+ # The following line is provided for convenience purposes. It has the downside
27
+ # of increasing the boot-up time by auto-requiring all files in the support
28
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
29
+ # require only the support files necessary.
30
+ #
31
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
32
+
33
+ # Checks for pending migration and applies them before tests are run.
34
+ # If you are not using ActiveRecord, you can remove this line.
35
+ ActiveRecord::Migrator.migrations_paths = 'spec/dummy/db/migrate'
36
+ ActiveRecord::Migration.maintain_test_schema!
37
+
38
+ RSpec.configure do |config|
39
+ config.expect_with(:rspec) { |c| c.syntax = :should }
40
+
41
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
42
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
43
+
44
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
45
+ # examples within a transaction, remove the following line or assign false
46
+ # instead of true.
47
+ config.use_transactional_fixtures = false
48
+
49
+ config.before(:suite) do
50
+ DatabaseCleaner.strategy = :transaction
51
+ # DatabaseCleaner.clean_with(:truncation)
52
+ # MuseumDummy::Application.load_tasks
53
+ # puts 'call rake'
54
+ # Rake::Task['db:seed'].invoke # loading seeds
55
+ end
56
+ config.around(:each) do |example|
57
+ DatabaseCleaner.cleaning do
58
+ example.run
59
+ end
60
+ end
61
+
62
+ # RSpec Rails can automatically mix in different behaviours to your tests
63
+ # based on their file location, for example enabling you to call `get` and
64
+ # `post` in specs under `spec/controllers`.
65
+ #
66
+ # You can disable this behaviour by removing the line below, and instead
67
+ # explicitly tag your specs with their type, e.g.:
68
+ #
69
+ # RSpec.describe UsersController, :type => :controller do
70
+ # # ...
71
+ # end
72
+ #
73
+ # The different available types are documented in the features, such as in
74
+ # https://relishapp.com/rspec/rspec-rails/docs
75
+ config.infer_spec_type_from_file_location!
76
+
77
+ # Filter lines from Rails gems in backtraces.
78
+ # config.filter_rails_from_backtrace!
79
+ # arbitrary gems may also be filtered via:
80
+ # config.filter_gems_from_backtrace("gem name")
81
+ end
82
+
83
+ Shoulda::Matchers.configure do |config|
84
+ config.integrate do |with|
85
+ with.test_framework :rspec
86
+ with.library :rails
87
+ end
88
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe Museum::CasesController do
4
4
  routes { Museum::Engine.routes }
data/spec/spec_helper.rb CHANGED
@@ -1,72 +1,92 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
- require File.expand_path("../dummy/config/environment", __FILE__)
3
-
4
- require 'coveralls'
5
- Coveralls.wear!
6
-
7
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
- $LOAD_PATH.unshift(File.dirname(__FILE__))
9
-
10
- require 'rspec/rails'
11
- # require 'rspec/autorun'
12
- require 'rspec/its'
13
- require 'rails/all'
14
-
15
- require 'factory_girl_rails'
16
-
17
- require 'database_cleaner'
18
- require 'shoulda/matchers'
19
- require 'museum'
20
-
21
- # Requires supporting ruby files with custom matchers and macros, etc,
22
- # in spec/support/ and its subdirectories.
23
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
24
-
25
- # Checks for pending migrations before tests are run.
26
- # If you are not using ActiveRecord, you can remove this line.
27
- ActiveRecord::Migration.maintain_test_schema!
28
-
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
29
19
  RSpec.configure do |config|
30
-
31
- config.before(:suite) do
32
- DatabaseCleaner.strategy = :truncation
33
- DatabaseCleaner.clean_with(:truncation)
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
32
  end
35
33
 
36
- config.before(:each) do
37
- DatabaseCleaner.start
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
38
41
  end
39
42
 
40
- config.after(:each) do
41
- DatabaseCleaner.clean
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
63
+ config.disable_monkey_patching!
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
42
73
  end
43
74
 
44
- config.infer_spec_type_from_file_location!
45
-
46
- # ## Mock Framework
47
- #
48
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
49
- #
50
- # config.mock_with :mocha
51
- # config.mock_with :flexmock
52
- # config.mock_with :rr
53
-
54
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
55
- # config.fixture_path = "#{::Rails.root}/spec/fixtures"
56
-
57
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
58
- # examples within a transaction, remove the following line or assign false
59
- # instead of true.
60
- # config.use_transactional_fixtures = true
61
-
62
- # If true, the base class of anonymous controllers will be inferred
63
- # automatically. This will be the default behavior in future versions of
64
- # rspec-rails.
65
- config.infer_base_class_for_anonymous_controllers = false
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
66
79
 
67
80
  # Run specs in random order to surface order dependencies. If you find an
68
81
  # order dependency and want to debug it, you can fix the order by providing
69
82
  # the seed, which is printed after each run.
70
83
  # --seed 1234
71
- config.order = "random"
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
72
92
  end
@@ -1,7 +1,7 @@
1
1
  shared_context 'case support' do
2
- let!(:dummy_package) { FactoryGirl.create(:case, :name => 'bootswitch') }
3
- let!(:next_package) { FactoryGirl.create(:case, :name => 'customizable_bootstrap') }
4
- let!(:last_package) { FactoryGirl.create(:case, :name => 'bootstrap_leather') }
5
- let!(:fresh_package) { FactoryGirl.create(:case, :name => 'bootstrap_pager').freshen }
6
- let!(:expired_package) { FactoryGirl.create(:case, :name => 'private_person', :updated_at => (Time.now - 14400).to_datetime) }
2
+ let!(:dummy_package) { Museum::Case.find_by_name('bootswitch') }
3
+ let!(:next_package) { Museum::Case.find_by_name('customizable_bootstrap') }
4
+ let!(:last_package) { Museum::Case.find_by_name('bootstrap_leather') }
5
+ let!(:fresh_package) { Museum::Case.find_by_name('bootstrap_pager').freshen }
6
+ let!(:expired_package) { Museum::Case.find_by_name('private_person') }
7
7
  end
@@ -0,0 +1,116 @@
1
+ shared_examples_for 'a successful page' do |options = {}|
2
+ context 'responds successfully' do
3
+ subject { response }
4
+ it { should be_success }
5
+ end
6
+ if options[:which_renders].present?
7
+ it_behaves_like 'a page rendering a template', options[:which_renders]
8
+ end
9
+ end
10
+ shared_examples_for 'a page rendering a template' do |template|
11
+ context "renders the #{template} template" do
12
+ subject { response }
13
+ it { should render_template(template) }
14
+ end
15
+ end
16
+ shared_examples_for 'an error response' do |http_status|
17
+ context "issues error response code #{http_status}" do
18
+ subject { response }
19
+ it { should have_http_status(http_status) }
20
+ end
21
+ end
22
+ shared_examples_for 'a redirect to' do |path|
23
+ context "redirects to #{path}" do
24
+ subject { response }
25
+ it { should redirect_to path_to_url(path) }
26
+ end
27
+ end
28
+ shared_examples_for 'a redirect matching' do |path_expression|
29
+ context "redirects matching #{path_expression}" do
30
+ subject { response.location }
31
+ it { should match path_expression }
32
+ end
33
+ end
34
+ shared_examples_for 'a redirect to sign in' do
35
+ it_behaves_like 'a redirect to', '/users/sign_in'
36
+ end
37
+ shared_examples_for 'a redirect with a message' do |path, options|
38
+ it_behaves_like 'a redirect matching', path
39
+ options.each do |key, value|
40
+ context "sets #{key.to_s} message" do
41
+ subject { flash[key] }
42
+ it { should eq value }
43
+ end
44
+ end
45
+ end
46
+ shared_examples_for 'an error response with message' do |message|
47
+ it_behaves_like 'an error response', :forbidden
48
+ context 'sets failure message' do
49
+ subject { flash[:error] }
50
+ it { should eq message }
51
+ end
52
+ end
53
+ shared_examples_for 'a 404 Not Found error' do
54
+ it_behaves_like 'an error response', :not_found
55
+ it_behaves_like 'a page rendering a template', '404'
56
+ end
57
+ shared_examples_for 'a page with a message' do |options|
58
+ it_behaves_like 'a successful page'
59
+ options.each do |key, value|
60
+ context "sets #{key.to_s} message" do
61
+ subject { flash[key] }
62
+ it { should eq value }
63
+ end
64
+ end
65
+ end
66
+ shared_examples_for 'a page with a message matching' do |options|
67
+ it_behaves_like 'a successful page'
68
+ options.each do |key, value|
69
+ context "sets #{key.to_s} message" do
70
+ subject { flash[key] }
71
+ it { should match value }
72
+ end
73
+ end
74
+ end
75
+ shared_examples_for 'a page with an error message' do |message|
76
+ it_behaves_like 'a page with a message', error: message
77
+ end
78
+ shared_examples_for 'a page with an alert message' do |message|
79
+ it_behaves_like 'a page with a message', alert: message
80
+ end
81
+ shared_examples_for 'a page with a notice message' do |message|
82
+ it_behaves_like 'a page with a message', notice: message
83
+ end
84
+ shared_examples_for 'a page with an error message matching' do |message|
85
+ it_behaves_like 'a page with a message matching', error: message
86
+ end
87
+ shared_examples_for 'a 403 Forbidden error' do
88
+ it_should_behave_like 'an error response with message', 'You are not authorized to access this page.'
89
+ end
90
+ shared_examples_for 'a redirect with error' do |path, message|
91
+ it_behaves_like 'a redirect to', path
92
+ context 'sets error' do
93
+ subject { flash[:error] }
94
+ it { should eq message }
95
+ end
96
+ end
97
+ shared_examples_for 'a redirect with notice' do |path, message|
98
+ it_behaves_like 'a redirect to', path
99
+ context 'sets notice' do
100
+ subject { flash[:notice] }
101
+ it { should eq message }
102
+ end
103
+ end
104
+ shared_examples_for 'a redirect with alert' do |path, message|
105
+ it_behaves_like 'a redirect to', path
106
+ context 'sets alert' do
107
+ subject { flash[:alert] }
108
+ it { should eq message }
109
+ end
110
+ end
111
+ shared_examples_for 'a response without error' do
112
+ context 'sets no errors' do
113
+ subject { flash[:error] }
114
+ it { should be nil }
115
+ end
116
+ end
@@ -1,4 +1,4 @@
1
1
  shared_context 'loupe support' do
2
- let!(:rubygems) { FactoryGirl.create(:loupe, :title => 'RubyGems', :uri_template => 'http://www.rubygems.org/api/v1/gems/%{name}.json') }
3
- let!(:github) { FactoryGirl.create(:loupe, :title => 'GitHub', :uri_template => 'https://api.github.com/repos/%{user}/%{name}') }
2
+ let!(:rubygems) { Museum::Loupe.find_by_title('RubyGems') }
3
+ let!(:github) { Museum::Loupe.find_by_title('GitHub') }
4
4
  end