memcached-manager 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.rspec +2 -0
  2. data/.travis.yml +19 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +133 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +72 -0
  7. data/Rakefile +57 -0
  8. data/VERSION +1 -0
  9. data/config.ru +8 -0
  10. data/features/api/create_memcached_key.feature +6 -0
  11. data/features/api/delete_memcached_key.feature +6 -0
  12. data/features/api/list_memcached_keys.feature +6 -0
  13. data/features/api/set_memcached_info.feature +5 -0
  14. data/features/api/show_memcached_key.feature +10 -0
  15. data/features/api/show_memcached_stats.feature +5 -0
  16. data/features/api/update_memcached_key.feature +7 -0
  17. data/features/step_definitions/api/create_memcached_key.rb +21 -0
  18. data/features/step_definitions/api/delete_memcached_key.rb +7 -0
  19. data/features/step_definitions/api/list_memcached_keys.rb +16 -0
  20. data/features/step_definitions/api/show_memcached_key.rb +18 -0
  21. data/features/step_definitions/api/show_memcached_stats.rb +3 -0
  22. data/features/step_definitions/api/update_memcached_key.rb +18 -0
  23. data/features/step_definitions/set_memcached_info.rb +25 -0
  24. data/features/step_definitions/webapp/create_memcached_key.rb +10 -0
  25. data/features/step_definitions/webapp/delete_memcached_key.rb +16 -0
  26. data/features/step_definitions/webapp/edit_memcached_key.rb +3 -0
  27. data/features/step_definitions/webapp/list_memcached_keys.rb +4 -0
  28. data/features/step_definitions/webapp/show_memcached_key.rb +4 -0
  29. data/features/step_definitions/webapp/show_memcached_stats.rb +5 -0
  30. data/features/support/env.rb +27 -0
  31. data/features/support/hooks.rb +3 -0
  32. data/features/webapp/create_memcached_key.feature +9 -0
  33. data/features/webapp/delete_memcached_key.feature +8 -0
  34. data/features/webapp/edit_memcached_key.feature +9 -0
  35. data/features/webapp/list_memcached_keys.feature +8 -0
  36. data/features/webapp/show_memcached_key.feature +7 -0
  37. data/features/webapp/show_memcached_stats.feature +6 -0
  38. data/lib/api.rb +85 -0
  39. data/lib/extensions/api_response.rb +15 -0
  40. data/lib/extensions/errors.rb +19 -0
  41. data/lib/extensions/memcached_connection.rb +15 -0
  42. data/lib/extensions/memcached_inspector.rb +49 -0
  43. data/lib/extensions/memcached_settings.rb +18 -0
  44. data/lib/extensions.rb +14 -0
  45. data/lib/public/images/glyphicons-halflings-white.png +0 -0
  46. data/lib/public/images/glyphicons-halflings.png +0 -0
  47. data/lib/public/javascripts/angular/controllers.js +86 -0
  48. data/lib/public/javascripts/angular/routes.js +66 -0
  49. data/lib/public/javascripts/angular/services/notification.js +16 -0
  50. data/lib/public/javascripts/angular/services/resources.js +20 -0
  51. data/lib/public/javascripts/angular/services/response.js +10 -0
  52. data/lib/public/javascripts/angular-resource.min.js +10 -0
  53. data/lib/public/javascripts/angular-ui-states.min.js +7 -0
  54. data/lib/public/javascripts/angular.min.js +161 -0
  55. data/lib/public/javascripts/application.js +18 -0
  56. data/lib/public/javascripts/jquery-1.9.1.min.js +5 -0
  57. data/lib/public/javascripts/noty/jquery.noty.js +547 -0
  58. data/lib/public/javascripts/noty/layouts/top.js +34 -0
  59. data/lib/public/javascripts/noty/themes/default.js +156 -0
  60. data/lib/public/javascripts/noty_config.js +25 -0
  61. data/lib/public/stylesheets/app.css +50 -0
  62. data/lib/public/stylesheets/base.css +269 -0
  63. data/lib/public/stylesheets/icons.css +492 -0
  64. data/lib/public/stylesheets/layout.css +58 -0
  65. data/lib/public/stylesheets/skeleton.css +242 -0
  66. data/lib/public/templates/edit.html.erb +6 -0
  67. data/lib/public/templates/keys.html.erb +36 -0
  68. data/lib/public/templates/new.html.erb +6 -0
  69. data/lib/public/templates/show.html.erb +2 -0
  70. data/lib/public/templates/stats.html.erb +8 -0
  71. data/lib/views/index.erb +13 -0
  72. data/lib/views/layout.erb +52 -0
  73. data/lib/webapp.rb +14 -0
  74. data/memcached-manager.gemspec +145 -0
  75. data/spec/javascripts/angular/controllers/list_keys_controller_spec.js +26 -0
  76. data/spec/javascripts/angular/services/notification_spec.js +45 -0
  77. data/spec/javascripts/angular/services/resource_spec.js +41 -0
  78. data/spec/javascripts/angular/services/response_spec.js +26 -0
  79. data/spec/javascripts/helpers/SpecHelper.js +2 -0
  80. data/spec/javascripts/helpers/angular-mocks.js +1962 -0
  81. data/spec/javascripts/support/jasmine.yml +96 -0
  82. data/spec/javascripts/support/jasmine_helper.rb +11 -0
  83. data/spec/lib/extensions/api_response_spec.rb +28 -0
  84. data/spec/lib/extensions/error_spec.rb +23 -0
  85. data/spec/lib/extensions/memcached_connection_spec.rb +25 -0
  86. data/spec/lib/extensions/memcached_inspector_spec.rb +41 -0
  87. data/spec/lib/extensions/memcached_settings_spec.rb +53 -0
  88. data/spec/spec_helper.rb +41 -0
  89. metadata +252 -0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ before_script:
2
+ - "export DISPLAY=:99.0"
3
+ - "sh -e /etc/init.d/xvfb start"
4
+
5
+ before_install:
6
+ - gem install bundler
7
+
8
+ script:
9
+ rake
10
+
11
+ rvm:
12
+ - 1.9.3
13
+ - 2.0.0
14
+
15
+ gemfile:
16
+ - Gemfile
17
+
18
+ services:
19
+ - memcache
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "sinatra"
4
+ gem "sinatra-contrib"
5
+ gem "dalli"
6
+ gem "poltergeist"
7
+
8
+ group :development do
9
+ gem "jeweler", "~> 1.8.8"
10
+ end
11
+
12
+ group :test do
13
+ gem "rack-test", :require => "rack/test"
14
+ gem "rspec"
15
+ gem "mocha"
16
+ gem "cucumber"
17
+ gem "capybara", :require => false
18
+ gem "faraday"
19
+ end
20
+
21
+ group :development, :test do
22
+ gem 'jasmine', "= 1.3.2"
23
+ gem "cucumber"
24
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ backports (3.3.4)
6
+ builder (3.2.2)
7
+ capybara (2.1.0)
8
+ mime-types (>= 1.16)
9
+ nokogiri (>= 1.3.3)
10
+ rack (>= 1.0.0)
11
+ rack-test (>= 0.5.4)
12
+ xpath (~> 2.0)
13
+ childprocess (0.3.9)
14
+ ffi (~> 1.0, >= 1.0.11)
15
+ cliver (0.2.2)
16
+ cucumber (1.3.8)
17
+ builder (>= 2.1.2)
18
+ diff-lcs (>= 1.1.3)
19
+ gherkin (~> 2.12.1)
20
+ multi_json (>= 1.7.5, < 2.0)
21
+ multi_test (>= 0.0.2)
22
+ dalli (2.6.4)
23
+ diff-lcs (1.2.4)
24
+ faraday (0.8.8)
25
+ multipart-post (~> 1.2.0)
26
+ ffi (1.9.0)
27
+ gherkin (2.12.1)
28
+ multi_json (~> 1.3)
29
+ git (1.2.6)
30
+ github_api (0.10.1)
31
+ addressable
32
+ faraday (~> 0.8.1)
33
+ hashie (>= 1.2)
34
+ multi_json (~> 1.4)
35
+ nokogiri (~> 1.5.2)
36
+ oauth2
37
+ hashie (2.0.5)
38
+ highline (1.6.19)
39
+ httpauth (0.2.0)
40
+ jasmine (1.3.2)
41
+ jasmine-core (~> 1.3.1)
42
+ rack (~> 1.0)
43
+ rspec (>= 1.3.1)
44
+ selenium-webdriver (>= 0.1.3)
45
+ jasmine-core (1.3.1)
46
+ jeweler (1.8.8)
47
+ builder
48
+ bundler (~> 1.0)
49
+ git (>= 1.2.5)
50
+ github_api (= 0.10.1)
51
+ highline (>= 1.6.15)
52
+ nokogiri (= 1.5.10)
53
+ rake
54
+ rdoc
55
+ json (1.8.0)
56
+ jwt (0.1.8)
57
+ multi_json (>= 1.5)
58
+ metaclass (0.0.1)
59
+ mime-types (1.25)
60
+ mocha (0.14.0)
61
+ metaclass (~> 0.0.1)
62
+ multi_json (1.8.0)
63
+ multi_test (0.0.2)
64
+ multi_xml (0.5.5)
65
+ multipart-post (1.2.0)
66
+ nokogiri (1.5.10)
67
+ oauth2 (0.9.2)
68
+ faraday (~> 0.8)
69
+ httpauth (~> 0.2)
70
+ jwt (~> 0.1.4)
71
+ multi_json (~> 1.0)
72
+ multi_xml (~> 0.5)
73
+ rack (~> 1.2)
74
+ poltergeist (1.4.1)
75
+ capybara (~> 2.1.0)
76
+ cliver (~> 0.2.1)
77
+ multi_json (~> 1.0)
78
+ websocket-driver (>= 0.2.0)
79
+ rack (1.5.2)
80
+ rack-protection (1.5.0)
81
+ rack
82
+ rack-test (0.6.2)
83
+ rack (>= 1.0)
84
+ rake (10.1.0)
85
+ rdoc (4.0.1)
86
+ json (~> 1.4)
87
+ rspec (2.14.1)
88
+ rspec-core (~> 2.14.0)
89
+ rspec-expectations (~> 2.14.0)
90
+ rspec-mocks (~> 2.14.0)
91
+ rspec-core (2.14.5)
92
+ rspec-expectations (2.14.2)
93
+ diff-lcs (>= 1.1.3, < 2.0)
94
+ rspec-mocks (2.14.3)
95
+ rubyzip (0.9.9)
96
+ selenium-webdriver (2.35.1)
97
+ childprocess (>= 0.2.5)
98
+ multi_json (~> 1.0)
99
+ rubyzip (< 1.0.0)
100
+ websocket (~> 1.0.4)
101
+ sinatra (1.4.3)
102
+ rack (~> 1.4)
103
+ rack-protection (~> 1.4)
104
+ tilt (~> 1.3, >= 1.3.4)
105
+ sinatra-contrib (1.4.1)
106
+ backports (>= 2.0)
107
+ multi_json
108
+ rack-protection
109
+ rack-test
110
+ sinatra (~> 1.4.0)
111
+ tilt (~> 1.3)
112
+ tilt (1.4.1)
113
+ websocket (1.0.7)
114
+ websocket-driver (0.3.0)
115
+ xpath (2.0.0)
116
+ nokogiri (~> 1.3)
117
+
118
+ PLATFORMS
119
+ ruby
120
+
121
+ DEPENDENCIES
122
+ capybara
123
+ cucumber
124
+ dalli
125
+ faraday
126
+ jasmine (= 1.3.2)
127
+ jeweler (~> 1.8.8)
128
+ mocha
129
+ poltergeist
130
+ rack-test
131
+ rspec
132
+ sinatra
133
+ sinatra-contrib
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Thiago Fernandes Massa
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/README.rdoc ADDED
@@ -0,0 +1,72 @@
1
+ = IN DEVELOPMENT, DON'T USE YET
2
+
3
+ == Memcached Manager
4
+
5
+ A sinatra memcached-manager that allows you to view status, flush/view keys and so on. Also easily pluggable to a Rails app.
6
+
7
+ {<img src="https://travis-ci.org/thiagofm/memcached-manager.png" />}[https://travis-ci.org/thiagofm/memcached-manager] {<img src="https://codeclimate.com/github/thiagofm/memcached-manager.png" />}[https://codeclimate.com/github/thiagofm/memcached-manager]
8
+
9
+ == Installation
10
+
11
+ 1. Install the gem.
12
+
13
+ gem install memcached-manager
14
+
15
+ 2. Run memcached-manager
16
+
17
+ memcached-manager
18
+
19
+ == Plugging memcached manager to an existing Rails app.
20
+
21
+ Todo.
22
+
23
+ == Roadmap
24
+
25
+ * Develop frontend & artwork (in progress)
26
+ * Favicon
27
+ * Generate GEM
28
+
29
+
30
+ == Should be done in the future
31
+
32
+ * Update API/frontend in order to use http statuses for errors, creation and so on.
33
+
34
+ == Running(for now...)
35
+
36
+ Just run:
37
+
38
+ bundle install
39
+ rackup
40
+
41
+ == Running the test suite
42
+
43
+ First, make sure you have phantomjs installed if you want to run cukes tagged as @javascript(those who are in the features/webapp directory.
44
+
45
+ Have `memcached` run on `localhost:11211` then run:
46
+
47
+ bundle exec rake
48
+
49
+ == Requirements
50
+
51
+ Ruby >= 1.9
52
+ Memcached (of course)
53
+
54
+ == Contributing to Memcached Manager
55
+
56
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
57
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
58
+ * Fork the project.
59
+ * Start a feature/bugfix branch.
60
+ * Commit and push until you are happy with your contribution.
61
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
62
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
63
+
64
+ == Maintainers
65
+
66
+ * thiagofm[http://github.com/thiagofm]
67
+
68
+ == Copyright
69
+
70
+ Copyright (c) 2013 Thiago Fernandes Massa. See LICENSE.txt for
71
+ further details.
72
+
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "memcached-manager"
18
+ gem.homepage = "http://github.com/thiagofm/memcached-manager"
19
+ gem.license = "MIT"
20
+ gem.summary = "A sinatra memcached-manager that allows you to view status, flush/view keys and so on. Also easily pluggable to a Rails app."
21
+ gem.description = "A sinatra memcached-manager that allows you to view status, flush/view keys and so on. Also easily pluggable to a Rails app."
22
+ gem.email = "thiagown@gmail.com"
23
+ gem.authors = ["Thiago Fernandes Massa"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ # Tests
29
+ begin
30
+ require 'jasmine'
31
+ load 'jasmine/tasks/jasmine.rake'
32
+ rescue LoadError
33
+ task :jasmine do
34
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
35
+ end
36
+ end
37
+
38
+ require 'cucumber'
39
+ require 'cucumber/rake/task'
40
+
41
+ Cucumber::Rake::Task.new(:features) do |t|
42
+ t.cucumber_opts = "features --format pretty"
43
+ end
44
+
45
+ require 'rspec/core/rake_task'
46
+
47
+ desc "Run specs"
48
+ RSpec::Core::RakeTask.new do |t|
49
+ t.pattern = "./spec/**/*_spec.rb"
50
+ end
51
+
52
+ task :jasmineci do
53
+ system("export DISPLAY=:99.0 && bundle exec rake jasmine:ci")
54
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
55
+ end
56
+
57
+ task :default => [:jasmineci, :features, :spec]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/config.ru ADDED
@@ -0,0 +1,8 @@
1
+ # Sinatra modules
2
+ require './lib/webapp'
3
+ require './lib/api'
4
+
5
+ run Rack::URLMap.new({
6
+ "/api" => MemcachedManager::API.new,
7
+ "/" => MemcachedManager::Webapp.new
8
+ })
@@ -0,0 +1,6 @@
1
+ @api
2
+ Feature: Create memcached pair
3
+ Scenario: Success
4
+ When I post some data to "/keys.json" in the API
5
+ Then I should receive a json response that it was saved successfully
6
+ And it should be saved in memcached
@@ -0,0 +1,6 @@
1
+ @api
2
+ Feature: Delete memcached key
3
+ Scenario: Success
4
+ Given there's the "username" memcached key avaiable
5
+ When I visit "/keys/username.json" in the API with the delete method
6
+ Then this key shouldn't exist.
@@ -0,0 +1,6 @@
1
+ @api
2
+ Feature: List memcached keys
3
+ Scenario: Success
4
+ Given there's some memcached keys avaiable
5
+ When I visit "/keys.json" in the API
6
+ Then I should receive a json response with those keys
@@ -0,0 +1,5 @@
1
+ @api
2
+ Feature: Set memcached info
3
+ Scenario: Success
4
+ When I post configs to "/config.json" in the API
5
+ Then the memcached config should be set
@@ -0,0 +1,10 @@
1
+ @api
2
+ Feature: Show memcached keys
3
+ Scenario: Success
4
+ Given there's the "username" memcached key avaiable
5
+ When I visit "/keys/username.json" in the API
6
+ Then I should receive a json response with this key
7
+
8
+ Scenario: Key doesn't exist
9
+ When I visit "/keys/username.json" in the API
10
+ Then I should receive a json telling me that the key doesn't exist
@@ -0,0 +1,5 @@
1
+ @api
2
+ Feature: Show memcached stats
3
+ Scenario: Success
4
+ When I visit "/stats.json" in the API
5
+ Then I should receive a json response with the memcached's current stats
@@ -0,0 +1,7 @@
1
+ @api
2
+ Feature: Update memcached pair
3
+ Scenario: Success
4
+ Given there's the "username" memcached key avaiable
5
+ When I put some data to "/keys.json" in the API
6
+ Then I should receive a json response that it was edited successfully
7
+ And it should be updated in memcached
@@ -0,0 +1,21 @@
1
+ When /^I post some data to "(.*?)" in the API$/ do |route|
2
+ @data = { key: 'all.i.want.to.do', value: 'is.bang.bang.bang' }
3
+ @response = API.post do |req|
4
+ req.url "api/#{route}"
5
+ req.params = @data
6
+ end
7
+ end
8
+
9
+ Then /^I should receive a json response that it was saved successfully$/ do
10
+ @response.status.should be 200
11
+ response_json = JSON.parse(@response.body)
12
+ response_json.class.should eql Hash
13
+ response_json.keys.should_not include 'errors'
14
+ response_json.values.should include 'all.i.want.to.do'
15
+ response_json.keys.should include 'expired'
16
+ end
17
+
18
+ Then /^it should be saved in memcached$/ do
19
+ key = Memcached.get(@data[:key])
20
+ key.should == @data[:value]
21
+ end
@@ -0,0 +1,7 @@
1
+ When /^I visit "(.*?)" in the API with the delete method$/ do |route|
2
+ API.delete("api/#{route}")
3
+ end
4
+
5
+ Then /^this key shouldn't exist\.$/ do
6
+ Memcached.get('username').should eql nil
7
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ Given /^there's some memcached keys avaiable$/ do
4
+ Memcached.set('foo', 'bar')
5
+ Memcached.set('ineed', 'togetalife')
6
+ end
7
+
8
+ When /^I visit "(.*?)" in the API$/ do |route|
9
+ @response = JSON.parse(API.get("api/#{route}").body)
10
+ end
11
+
12
+ Then /^I should receive a json response with those keys$/ do
13
+ @response.should_not equal nil
14
+ @response.last.values.should include 'foo'
15
+ @response.first.values.should include 'ineed'
16
+ end
@@ -0,0 +1,18 @@
1
+ # Scenario: Success
2
+ Given /^there's the "(.*?)" memcached key avaiable$/ do |key|
3
+ @key = key
4
+ Memcached.set(@key, 'John Doe')
5
+ end
6
+
7
+ Then /^I should receive a json response with this key$/ do
8
+ @response.class.should eql Hash
9
+ @response["key"].should include 'name'
10
+ @response["value"].should include 'John Doe'
11
+ end
12
+
13
+ # Scenario: Key doesn't exist
14
+ Then /^I should receive a json telling me that the key doesn't exist$/ do
15
+ @response.class.should eql Hash
16
+ @response.keys.should include 'errors'
17
+ @response["errors"].should include 'Key not found.'
18
+ end
@@ -0,0 +1,3 @@
1
+ Then /^I should receive a json response with the memcached's current stats$/ do
2
+ @response.keys.should include("#{MemcachedConfigs[:host]}:#{MemcachedConfigs[:port]}")
3
+ end
@@ -0,0 +1,18 @@
1
+ When /^I put some data to "(.*?)" in the API$/ do |route|
2
+ @data = { key: 'username', value: 'thiagofm' }
3
+ @response = API.put do |req|
4
+ req.url "api/#{route}"
5
+ req.params = @data
6
+ end
7
+ end
8
+
9
+ Then /^I should receive a json response that it was edited successfully$/ do
10
+ @response.status.should be 200
11
+ response_json = JSON.parse(@response.body)
12
+ response_json.class.should eql Hash
13
+ response_json.keys.should include 'key'
14
+ end
15
+
16
+ Then /^it should be updated in memcached$/ do
17
+ Memcached.get(@key).should eql 'thiagofm'
18
+ end
@@ -0,0 +1,25 @@
1
+ When /^I post configs to "(.*?)" in the API$/ do |route|
2
+ @data = { 'host' => 'i.am', 'port' => '1337' }
3
+ @route = route
4
+
5
+ API.post do |req|
6
+ req.url "api/#{@route}"
7
+ req.params = @data
8
+ end
9
+ end
10
+
11
+ Then /^the memcached config should be set$/ do
12
+ response = API.get("api/#{@route}")
13
+ response_json = JSON.parse(response.body)
14
+
15
+ response.status.should be 200
16
+ response_json['host'].should eql @data['host']
17
+ response_json['port'].should eql @data['port']
18
+
19
+ # Workaround so the next feature don't use the current memcached configs
20
+ @data = { 'host' => MemcachedConfigs[:host], 'port' => MemcachedConfigs[:port] }
21
+ API.post do |req|
22
+ req.url "api/#{@route}"
23
+ req.params = @data
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ When /^click on the X inside a div$/ do
2
+ within(".key-actions") do
3
+ find('.icon-remove').click
4
+ end
5
+ sleep 5
6
+ end
7
+
8
+ Then /^"(.*?)" key shouldn't exist in memcached$/ do |key|
9
+ Memcached.get(key).should be nil
10
+ end
@@ -0,0 +1,16 @@
1
+ When /^I visit "(.*?)"$/ do |route|
2
+ visit route
3
+ end
4
+
5
+ When /^fill in "(.*?)" with "(.*?)"$/ do |field, value|
6
+ fill_in(field, :with => value)
7
+ end
8
+
9
+ When /^click "(.*?)"$/ do |button|
10
+ click_button button
11
+ end
12
+
13
+ Then /^"(.*?)" key should have the "(.*?)" value in memcached$/ do |key, value|
14
+ sleep 1
15
+ Memcached.get(key).should == value
16
+ end
@@ -0,0 +1,3 @@
1
+ Given /^a key named "(.*?)" with the content "(.*?)" exists$/ do |key, value|
2
+ Memcached.set(key, value)
3
+ end
@@ -0,0 +1,4 @@
1
+ Then /^I should see "(.*?)" and "(.*?)" keys in the listing$/ do |key1, key2|
2
+ page.should have_content(key1)
3
+ page.should have_content(key2)
4
+ end
@@ -0,0 +1,4 @@
1
+ Then /^I should be able to see the "(.*?)" key with the "(.*?)" value$/ do |key, value|
2
+ page.should have_content(key)
3
+ page.should have_content(value)
4
+ end
@@ -0,0 +1,5 @@
1
+ Then /^I should see memcached stats$/ do
2
+ page.should have_content('Stats')
3
+ page.should have_content("#{MemcachedConfigs[:host]}")
4
+ page.should have_content("#{MemcachedConfigs[:port]}")
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'cucumber'
2
+ require 'capybara/cucumber'
3
+ require 'faraday'
4
+ require 'dalli'
5
+ require 'rspec'
6
+ require 'rspec/expectations'
7
+ require 'capybara/poltergeist'
8
+
9
+ Capybara.javascript_driver = :poltergeist
10
+
11
+ World(RSpec::Matchers)
12
+
13
+ # Files
14
+ Dir.glob("lib/**/*.rb").each do |file|
15
+ require_relative "../../#{file}"
16
+ end
17
+
18
+ Capybara.app = Rack::Builder.parse_file(File.expand_path('../../../config.ru', __FILE__)).first
19
+
20
+ API = Faraday.new do |conn| conn.adapter :rack, Rack::URLMap.new({
21
+ "/api" => MemcachedManager::API.new,
22
+ "/" => MemcachedManager::Webapp.new
23
+ })
24
+ end
25
+
26
+ MemcachedConfigs = { host: 'localhost', port: '11211' }
27
+ Memcached = Dalli::Client.new("#{MemcachedConfigs[:host]}:#{MemcachedConfigs[:port]}")
@@ -0,0 +1,3 @@
1
+ After do
2
+ Memcached.flush
3
+ end
@@ -0,0 +1,9 @@
1
+ @webapp
2
+ @javascript
3
+ Feature: Create memcached pair
4
+ Scenario: Success
5
+ When I visit "#/new"
6
+ And fill in "Key" with "foo"
7
+ And fill in "Value" with "bar"
8
+ And click "Create"
9
+ Then "foo" key should have the "bar" value in memcached
@@ -0,0 +1,8 @@
1
+ @webapp
2
+ @javascript
3
+ Feature: Delete memcached pair
4
+ Scenario: Success
5
+ Given a key named "foo" with the content "bar" exists
6
+ When I visit "#/"
7
+ And click on the X inside a div
8
+ Then "foo" key shouldn't exist in memcached
@@ -0,0 +1,9 @@
1
+ @webapp
2
+ @javascript
3
+ Feature: Edit memcached pair
4
+ Scenario: Success
5
+ Given a key named "foo" with the content "bar" exists
6
+ When I visit "#/edit/foo"
7
+ And fill in "Value" with "baz"
8
+ And click "Edit"
9
+ Then "foo" key should have the "baz" value in memcached
@@ -0,0 +1,8 @@
1
+ @webapp
2
+ @javascript
3
+ Feature: List memcached pair
4
+ Scenario: Success
5
+ Given a key named "foo" with the content "bar" exists
6
+ And a key named "fu" with the content "bar" exists
7
+ When I visit "#/"
8
+ Then I should see "foo" and "fu" keys in the listing
@@ -0,0 +1,7 @@
1
+ @webapp
2
+ @javascript
3
+ Feature: Show memcached key
4
+ Scenario: Success
5
+ Given a key named "foo" with the content "bar" exists
6
+ When I visit "#/key/foo"
7
+ Then I should be able to see the "foo" key with the "bar" value
@@ -0,0 +1,6 @@
1
+ @webapp
2
+ @javascript
3
+ Feature: Show memcached stats
4
+ Scenario: Success
5
+ When I visit "#/"
6
+ Then I should see memcached stats