power_shop 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/spec/controllers/cart_controller_spec.rb +56 -0
- data/spec/controllers/catalog_controller_spec.rb +77 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +3 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +105 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +85730 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/categories.rb +5 -0
- data/spec/factories/order.rb +4 -0
- data/spec/factories/products.rb +13 -0
- data/spec/factories/shopping_cart.rb +5 -0
- data/spec/lib/middleware/shopping_cart_spec.rb +25 -0
- data/spec/models/category_spec.rb +68 -0
- data/spec/models/order_item_spec.rb +13 -0
- data/spec/models/order_spec.rb +13 -0
- data/spec/models/product_spec.rb +24 -0
- data/spec/models/shop_image_spec.rb +11 -0
- data/spec/spec_helper.rb +31 -0
- metadata +382 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
describe PowerShop::Middleware::ShoppingCart do
|
5
|
+
let(:app) do
|
6
|
+
Rack::Builder.new do
|
7
|
+
use PowerShop::Middleware::ShoppingCart
|
8
|
+
run ->(env) { [200, {'Content-Type' => "text/html"}, ['Hello world!']] }
|
9
|
+
end.to_app
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:request) { Rack::MockRequest.new(app) }
|
13
|
+
let(:session) { ActionController::TestSession.new }
|
14
|
+
|
15
|
+
it 'creates shopping cart' do
|
16
|
+
request.get(
|
17
|
+
'http://www.myshop.com',
|
18
|
+
'REQUEST_URI' => '/',
|
19
|
+
'HTTP_HOST' => 'www.myshop.com',
|
20
|
+
'rack.session' => session
|
21
|
+
)
|
22
|
+
|
23
|
+
expect(::ShoppingCart.exists?(session[:shopping_cart_id])).to eq true
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Category do
|
5
|
+
describe 'schema' do
|
6
|
+
it { expect(subject).to have_db_column(:name).of_type(:string) }
|
7
|
+
it { expect(subject).to have_db_column(:slug).of_type(:string) }
|
8
|
+
it { expect(subject).to have_db_column(:parent_id).of_type(:integer) }
|
9
|
+
it { expect(subject).to have_db_column(:lft).of_type(:integer) }
|
10
|
+
it { expect(subject).to have_db_column(:rgt).of_type(:integer) }
|
11
|
+
it { expect(subject).to have_db_column(:depth).of_type(:integer) }
|
12
|
+
it { expect(subject).to have_db_column(:created_at) }
|
13
|
+
it { expect(subject).to have_db_column(:updated_at) }
|
14
|
+
it { expect(subject).to have_db_column(:description) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'associations' do
|
18
|
+
it { expect(subject).to have_many(:products) }
|
19
|
+
it { expect(subject).to have_one(:image) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'validations' do
|
23
|
+
it { expect(subject).to validate_presence_of(:name) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'delete' do
|
27
|
+
let(:product) { create :product}
|
28
|
+
let(:category) { product.category }
|
29
|
+
|
30
|
+
it 'delete category products after delete category' do
|
31
|
+
expect { category.destroy! }.to change { category.products.count }.by(-1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#products_count' do
|
36
|
+
context 'when product active' do
|
37
|
+
let(:active_product) { create :product, active: true }
|
38
|
+
subject(:category) { active_product.category.reload }
|
39
|
+
|
40
|
+
it { expect(category.products_count).to eq 1 }
|
41
|
+
it 'changes products count' do
|
42
|
+
expect{ active_product.destroy! }
|
43
|
+
.to change { category.reload.products_count }.by(-1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'changes products count' do
|
47
|
+
active_product.update_attributes(active: false)
|
48
|
+
expect(category.products_count).to eq 0
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when product disabled' do
|
53
|
+
let(:disabled_product) { create :disabled_product }
|
54
|
+
subject(:category) { disabled_product.category.reload }
|
55
|
+
|
56
|
+
it { expect(category.products_count).to eq 0 }
|
57
|
+
it 'not changes products count' do
|
58
|
+
disabled_product.destroy!
|
59
|
+
expect(category.products_count).to eq 0
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'changes products count' do
|
63
|
+
disabled_product.update_attributes(active: true)
|
64
|
+
expect(category.products_count).to eq 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OrderItem do
|
4
|
+
describe 'schema' do
|
5
|
+
it { expect(subject).to have_db_column(:order_id).of_type(:integer) }
|
6
|
+
it { expect(subject).to have_db_column(:product_id).of_type(:integer) }
|
7
|
+
it { expect(subject).to have_db_column(:product_title).of_type(:string) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'associations' do
|
11
|
+
it { expect(subject).to belong_to(:order) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Order do
|
4
|
+
describe 'schema' do
|
5
|
+
it { expect(subject).to have_db_column(:user_name).of_type(:string) }
|
6
|
+
it { expect(subject).to have_db_column(:user_email).of_type(:string) }
|
7
|
+
it { expect(subject).to have_db_column(:user_phone).of_type(:string) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'associations' do
|
11
|
+
it { expect(subject).to have_many(:order_items) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Product do
|
4
|
+
describe 'schema' do
|
5
|
+
it { expect(subject).to have_db_column(:name).of_type(:string) }
|
6
|
+
it { expect(subject).to have_db_column(:category_id).of_type(:integer) }
|
7
|
+
it { expect(subject).to have_db_column(:slug).of_type(:string) }
|
8
|
+
it { expect(subject).to have_db_column(:description).of_type(:text) }
|
9
|
+
it { expect(subject).to have_db_column(:price).of_type(:float) }
|
10
|
+
it { expect(subject).to have_db_column(:description).of_type(:text) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'associations' do
|
14
|
+
it { expect(subject).to belong_to(:category) }
|
15
|
+
it { expect(subject).to have_many(:images) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'validations' do
|
19
|
+
it { expect(subject).to validate_presence_of(:name) }
|
20
|
+
it { expect(subject).to validate_presence_of(:category_id) }
|
21
|
+
it { expect(subject).to validate_presence_of(:price) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ShopImage do
|
4
|
+
describe 'schema' do
|
5
|
+
it { expect(subject).to have_db_column(:subject_id).of_type(:integer) }
|
6
|
+
it { expect(subject).to have_db_column(:subject_type).of_type(:string) }
|
7
|
+
it { expect(subject).to have_db_column(:image).of_type(:string) }
|
8
|
+
it { expect(subject).to have_db_column(:created_at) }
|
9
|
+
it { expect(subject).to have_db_column(:updated_at) }
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
require File.expand_path("../dummy/config/application.rb", __FILE__)
|
8
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
9
|
+
|
10
|
+
require 'rspec/rails'
|
11
|
+
require 'factory_girl_rails'
|
12
|
+
require 'shoulda/matchers'
|
13
|
+
|
14
|
+
Rails.backtrace_cleaner.remove_silencers!
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.include FactoryGirl::Syntax::Methods
|
18
|
+
|
19
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
20
|
+
# examples within a transaction, remove the following line or assign false
|
21
|
+
# instead of true.
|
22
|
+
config.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# If true, the base class of anonymous controllers will be inferred
|
25
|
+
# automatically. This will be the default behavior in future versions of
|
26
|
+
# rspec-rails.
|
27
|
+
config.infer_base_class_for_anonymous_controllers = false
|
28
|
+
config.order = "random"
|
29
|
+
|
30
|
+
ActiveSupport::Deprecation.silenced = true
|
31
|
+
end
|