hide_and_seek 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/hide_and_seek/application.js +13 -0
  5. data/app/assets/stylesheets/hide_and_seek/application.css +15 -0
  6. data/app/controllers/hide_and_seek/application_controller.rb +4 -0
  7. data/app/controllers/hide_and_seek/items_controller.rb +34 -0
  8. data/app/helpers/hide_and_seek/application_helper.rb +4 -0
  9. data/app/helpers/hide_and_seek/item_helper.rb +4 -0
  10. data/app/models/hide_and_seek/item.rb +28 -0
  11. data/app/views/layouts/hide_and_seek/application.html.erb +14 -0
  12. data/config/routes.rb +3 -0
  13. data/lib/hide_and_seek.rb +4 -0
  14. data/lib/hide_and_seek/engine.rb +13 -0
  15. data/lib/hide_and_seek/version.rb +3 -0
  16. data/lib/tasks/hide_and_seek_tasks.rake +4 -0
  17. data/spec/hide_and_seek/controllers/items_controller_spec.rb +55 -0
  18. data/spec/hide_and_seek/models/item_spec.rb +45 -0
  19. data/spec/internal/README.rdoc +28 -0
  20. data/spec/internal/Rakefile +6 -0
  21. data/spec/internal/app/assets/javascripts/application.js +13 -0
  22. data/spec/internal/app/assets/stylesheets/application.css +15 -0
  23. data/spec/internal/app/controllers/application_controller.rb +5 -0
  24. data/spec/internal/app/helpers/application_helper.rb +2 -0
  25. data/spec/internal/app/views/layouts/application.html.erb +14 -0
  26. data/spec/internal/bin/bundle +3 -0
  27. data/spec/internal/bin/rails +4 -0
  28. data/spec/internal/bin/rake +4 -0
  29. data/spec/internal/bin/setup +29 -0
  30. data/spec/internal/config.ru +4 -0
  31. data/spec/internal/config/application.rb +32 -0
  32. data/spec/internal/config/boot.rb +5 -0
  33. data/spec/internal/config/database.yml +25 -0
  34. data/spec/internal/config/environment.rb +5 -0
  35. data/spec/internal/config/environments/development.rb +41 -0
  36. data/spec/internal/config/environments/production.rb +79 -0
  37. data/spec/internal/config/environments/test.rb +42 -0
  38. data/spec/internal/config/initializers/assets.rb +11 -0
  39. data/spec/internal/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/internal/config/initializers/cookies_serializer.rb +3 -0
  41. data/spec/internal/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/spec/internal/config/initializers/hide_and_seek.rb +6 -0
  43. data/spec/internal/config/initializers/inflections.rb +16 -0
  44. data/spec/internal/config/initializers/mime_types.rb +4 -0
  45. data/spec/internal/config/initializers/session_store.rb +3 -0
  46. data/spec/internal/config/initializers/wrap_parameters.rb +14 -0
  47. data/spec/internal/config/locales/en.yml +23 -0
  48. data/spec/internal/config/routes.rb +3 -0
  49. data/spec/internal/config/secrets.yml +22 -0
  50. data/spec/internal/db/combustion_test.sqlite +0 -0
  51. data/spec/internal/db/schema.rb +3 -0
  52. data/spec/internal/db/test.sqlite3 +0 -0
  53. data/spec/internal/log/development.log +0 -0
  54. data/spec/internal/log/test.log +2924 -0
  55. data/spec/internal/public/404.html +67 -0
  56. data/spec/internal/public/422.html +67 -0
  57. data/spec/internal/public/500.html +66 -0
  58. data/spec/internal/public/favicon.ico +0 -0
  59. data/spec/spec_helper.rb +29 -0
  60. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7a671a6be853fb8677d508e509ac72018054a44
4
+ data.tar.gz: f8a7c55aa728293551a78c63a460a7dbb41f3d31
5
+ SHA512:
6
+ metadata.gz: 2052593c7e833f02ff7786f2632144b4b78e62dd7e521fc105b46f238da99f7edd83a1423bddacd655eba8ebb375688afd2edfda029c5904c7f4d700c7b1ed00
7
+ data.tar.gz: 9984090693fabf0ccf834fbf33b091ee8896ceded5a7fe52514eb2ddc4a71f39b33e633eb6aafafc9f6bb4e676195e3fa0b74f36de86591a41b52fc364cc7072
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 BJ Clark
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+ Bundler.require
7
+
8
+ require 'rdoc/task'
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'HideAndSeek'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.rdoc')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ Bundler::GemHelper.install_tasks
19
+
20
+ require 'combustion'
21
+ task :environment do
22
+ Combustion.initialize!
23
+ end
24
+ Combustion::Application.load_tasks
25
+
26
+ desc 'Default: run spec tests.'
27
+ task :default => :spec
28
+
29
+ require "rspec/core/rake_task"
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = Dir.glob(['spec/hide_and_seek/**/*'])
32
+ spec.rspec_opts = ['--backtrace']
33
+ end
34
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module HideAndSeek
2
+ class ApplicationController < ::ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,34 @@
1
+ require_dependency "hide_and_seek/application_controller"
2
+
3
+ module HideAndSeek
4
+ class ItemsController < ApplicationController
5
+ before_filter :determine_identifier
6
+
7
+ def show
8
+ respond_to do |format|
9
+ format.json {
10
+ render json: [display: $hide_and_seek.display?(params[:id], @id)]
11
+ }
12
+ end
13
+ end
14
+
15
+ def update
16
+ respond_to do |format|
17
+ format.json do
18
+ if $hide_and_seek.hide(params[:id], @id)
19
+ render status: 200, json: [true]
20
+ else
21
+ render status: 502, json: [false]
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ private
29
+ def determine_identifier
30
+ @id = params[:user_id] || current_user.id
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module HideAndSeek
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module HideAndSeek
2
+ module ItemHelper
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ class HideAndSeek::Item
2
+ attr_accessor :item_name, :user_identifier
3
+
4
+ def initialize(storage)
5
+ @storage = storage
6
+ end
7
+
8
+ def display?(item_name, user_identifier)
9
+ @item_name = item_name
10
+ @user_identifier = user_identifier
11
+ return true if $redis.exists(key_name) == 1
12
+ return false
13
+ end
14
+
15
+ def hide(item_name, user_identifier)
16
+ @item_name = item_name
17
+ @user_identifier = user_identifier
18
+ if $redis.set(key_name, Time.now) == "OK"
19
+ return true
20
+ end
21
+ return false
22
+ end
23
+
24
+ def key_name
25
+ "#{@item_name}-#{@user_identifier}"
26
+ end
27
+
28
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HideAndSeek</title>
5
+ <%= stylesheet_link_tag "hide_and_seek/application", media: "all" %>
6
+ <%= javascript_include_tag "hide_and_seek/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ HideAndSeek::Engine.routes.draw do
2
+ resources :items, only: [:show, :update]
3
+ end
@@ -0,0 +1,4 @@
1
+ require "hide_and_seek/engine"
2
+
3
+ module HideAndSeek
4
+ end
@@ -0,0 +1,13 @@
1
+ module HideAndSeek
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace HideAndSeek
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, :fixture => false
7
+ end
8
+
9
+ Engine.routes.draw do
10
+ resources :items, only: [:show, :update]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module HideAndSeek
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hide_and_seek do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe HideAndSeek::ItemsController, :type => :controller do
4
+ routes { HideAndSeek::Engine.routes }
5
+
6
+ let(:current_user){double("User", :id => 1)}
7
+
8
+ before do
9
+ allow(controller).to receive(:current_user).and_return(current_user)
10
+ end
11
+
12
+
13
+ context "#show" do
14
+ it "should check hide_and_seek with the id and the current user" do
15
+ expect($hide_and_seek).to receive(:display?).with("foo", 1).and_return(true)
16
+ get :show, id: "foo", format: :json
17
+ end
18
+ it "should render json display => true if successful" do
19
+ allow($hide_and_seek).to receive(:display?).and_return true
20
+ get :show, id: "foo", format: :json
21
+ expect(response.body).to eq([display: true].to_json)
22
+ end
23
+ it "should render json display => false if unsuccessful" do
24
+ allow($hide_and_seek).to receive(:display?).and_return false
25
+ get :show, id: "foo", format: :json
26
+ expect(response.body).to eq([display: false].to_json)
27
+ end
28
+ it "should params[:user_id] over current_user if sent" do
29
+ expect($hide_and_seek).to receive(:display?).with("foo", 9001).and_return(true)
30
+ get :show, id: "foo", format: :json, user_id: 9001
31
+ end
32
+ end
33
+
34
+ context "#update" do
35
+ it "should hide the item for the current_user" do
36
+ expect($hide_and_seek).to receive(:hide).with("foo", 1)
37
+ patch :update, id: "foo", format: :json
38
+ end
39
+ it "should render 200" do
40
+ allow($hide_and_seek).to receive(:hide).and_return true
41
+ patch :update, id: "foo", format: :json
42
+ expect(response.status).to eq(200)
43
+ end
44
+ it "should respond with 502 if it can't be saved." do
45
+ allow($hide_and_seek).to receive(:hide).and_return false
46
+ patch :update, id: "foo", format: :json
47
+ expect(response.status).to eq(502)
48
+ end
49
+ it "should params[:user_id] over current_user if sent" do
50
+ expect($hide_and_seek).to receive(:hide).with("foo", 9001).and_return(true)
51
+ patch :update, id: "foo", format: :json, user_id: 9001
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe HideAndSeek::Item, :type => :model do
4
+ before do
5
+ $redis = double(:exists => true, :set => "OK")
6
+ end
7
+
8
+ subject{HideAndSeek::Item.new $redis}
9
+
10
+ describe "#display?" do
11
+ it "should return true if key exists" do
12
+ allow($redis).to receive(:exists).with("foo-1").and_return 1
13
+ expect(subject.display?("foo", 1)).to be true
14
+ end
15
+ it "should return false if key doesn't exist" do
16
+ allow($redis).to receive(:exists).with("foo-1").and_return 0
17
+ expect(subject.display?("foo", 1)).to be false
18
+ end
19
+ end
20
+
21
+ describe "#key_name" do
22
+ it "should join the item name and the user identifier" do
23
+ subject.item_name = "foo"
24
+ subject.user_identifier = 1
25
+ expect(subject.key_name).to eql "foo-1"
26
+ end
27
+
28
+ end
29
+
30
+ describe "#hide" do
31
+ it "should receive a key with the current time" do
32
+ expect($redis).to receive(:set).with("foo-1", anything())
33
+ subject.hide("foo", 1)
34
+ end
35
+ it "should return true if successful" do
36
+ allow($redis).to receive(:set).with("foo-1", anything()).and_return "OK"
37
+ expect(subject.hide("foo", 1)).to be true
38
+ end
39
+
40
+ it "should return false if unsuccessful" do
41
+ allow($redis).to receive(:set).and_return "FALSE"
42
+ expect(subject.hide("foo", 1)).to be false
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Internal</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'