seory 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/Gemfile +1 -0
  4. data/README.md +20 -17
  5. data/lib/seory.rb +25 -4
  6. data/lib/seory/condition.rb +29 -0
  7. data/lib/seory/{page_condition/block_condition.rb → condition/block.rb} +2 -2
  8. data/lib/seory/condition/build_dsl.rb +19 -0
  9. data/lib/seory/{page_condition/params_condition.rb → condition/params.rb} +2 -2
  10. data/lib/seory/{page_condition/path_condition.rb → condition/path.rb} +2 -2
  11. data/lib/seory/{page_condition/slug_condition.rb → condition/slug.rb} +5 -3
  12. data/lib/seory/dsl.rb +12 -49
  13. data/lib/seory/dsl/descriptor.rb +29 -0
  14. data/lib/seory/dsl/page_builder.rb +35 -0
  15. data/lib/seory/page.rb +53 -0
  16. data/lib/seory/page_group.rb +15 -0
  17. data/lib/seory/rails_helper.rb +7 -0
  18. data/lib/seory/railtie.rb +11 -0
  19. data/lib/seory/repository.rb +40 -6
  20. data/lib/seory/runtime.rb +13 -6
  21. data/lib/seory/version.rb +1 -1
  22. data/seory.gemspec +1 -0
  23. data/spec/seory/{page_condition/path_condition_spec.rb → condition/path_spec.rb} +3 -3
  24. data/spec/seory/condition/slug_spec.rb +18 -0
  25. data/spec/seory/dsl_spec.rb +23 -5
  26. data/spec/seory/{page_contents_spec.rb → page_spec.rb} +12 -12
  27. data/spec/seory/rails_helper_spec.rb +62 -0
  28. data/spec/seory/repository_spec.rb +103 -0
  29. data/spec/seory/runtime_spec.rb +25 -6
  30. data/spec/spec_helper.rb +8 -0
  31. data/spec/support/controller_double.rb +37 -0
  32. data/spec/support/testing_dsl.rb +7 -0
  33. data/spec/support/view_context_double.rb +13 -0
  34. metadata +44 -14
  35. data/lib/seory/page_condition.rb +0 -32
  36. data/lib/seory/page_condition/build_dsl.rb +0 -19
  37. data/lib/seory/page_condition/default_condition.rb +0 -10
  38. data/lib/seory/page_contents.rb +0 -41
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'seory/runtime'
3
- require 'seory/page_contents'
3
+ require 'seory/page'
4
4
 
5
5
  describe Seory::Runtime do
6
6
  let(:seory) do
@@ -8,7 +8,7 @@ describe Seory::Runtime do
8
8
  end
9
9
 
10
10
  let(:controller) { double('controller') }
11
- let(:page_contents) { Seory::PageContents.new(:default) }
11
+ let(:page_contents) { Seory::Page.new(:default) }
12
12
 
13
13
  context 'static content' do
14
14
  before do
@@ -26,9 +26,9 @@ describe Seory::Runtime do
26
26
  end
27
27
 
28
28
  context 'controller based dynamic content' do
29
- before do
30
- allow(controller).to receive(:action_name) { 'edit' }
29
+ let(:controller) { controller_double('foo#edit') }
31
30
 
31
+ before do
32
32
  page_contents.define(:title) { "#{action_name.upcase} | My Site" }
33
33
  end
34
34
 
@@ -38,13 +38,32 @@ describe Seory::Runtime do
38
38
  end
39
39
 
40
40
  context 'Access controller assigns(instance variables)' do
41
- before do
42
- allow(controller).to receive(:view_assigns).and_return('products' => [:products] * 42)
41
+ let(:controller) do
42
+ controller_double('foo#bar') { @products = [:products] * 42 }
43
+ end
43
44
 
45
+ before do
44
46
  page_contents.define(:title) { "Good Shop with #{assigns(:products).size} products!" }
45
47
  end
46
48
 
47
49
  specify { expect(seory.title).to eq 'Good Shop with 42 products!' }
50
+
51
+ context 'define accesssor to assigns() value' do
52
+ before do
53
+ page_contents.assign_reader(:products)
54
+ page_contents.define(:h1) { "See #{products.size} products." }
55
+ end
56
+
57
+ specify { expect(seory.h1).to eq 'See 42 products.' }
58
+ end
59
+
60
+ context 'cannnot alias reserved name' do
61
+ specify do
62
+ expect {
63
+ page_contents.assign_reader(:title)
64
+ }.to raise_error(Seory::AccessorNameTaken)
65
+ end
66
+ end
48
67
  end
49
68
 
50
69
  context 'Custom content created by misc()' do
@@ -13,6 +13,13 @@
13
13
  # users commonly want.
14
14
  #
15
15
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ if ENV['CODECLIMATE_REPO_TOKEN'] && RUBY_VERSION.start_with?('2.1')
17
+ require 'codeclimate-test-reporter'
18
+ CodeClimate::TestReporter.start
19
+ end
20
+
21
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each {|f| require f}
22
+
16
23
  RSpec.configure do |config|
17
24
  # The settings below are suggested to provide a good initial experience
18
25
  # with RSpec, but feel free to customize to your heart's content.
@@ -79,4 +86,5 @@ RSpec.configure do |config|
79
86
  mocks.verify_partial_doubles = true
80
87
  end
81
88
  =end
89
+ config.include Seory::TestingDsl
82
90
  end
@@ -0,0 +1,37 @@
1
+ module Seory
2
+ class ControllerDouble
3
+ attr_reader :params
4
+
5
+ def initialize(slug, params = {}, &block)
6
+ @__slug = slug
7
+ @params = params
8
+
9
+ instance_eval(&block) if block
10
+ end
11
+
12
+ def controller_name
13
+ controller_path.split('/').last
14
+ end
15
+
16
+ def controller_path
17
+ @__slug.split('#').first
18
+ end
19
+
20
+ def action_name
21
+ @__slug.split('#').last
22
+ end
23
+
24
+ def params
25
+ @params.merge(controller: controller_path, action: action_name)
26
+ end
27
+
28
+ def view_assigns
29
+ instance_variables.each_with_object({}) do |ivar, assigns|
30
+ name = ivar.to_s
31
+ next if name.start_with?('@__') || name == '@params'
32
+
33
+ assigns[name[1..-1]] = instance_variable_get(ivar)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Seory
2
+ module TestingDsl
3
+ def controller_double(*args, &block)
4
+ Seory::ControllerDouble.new(*args, &block)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'seory/rails_helper'
2
+
3
+ module Seory
4
+ class ViewContextDouble
5
+ include Seory::RailsHelper
6
+
7
+ attr_reader :controller
8
+
9
+ def initialize(controller)
10
+ @controller = controller
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - moro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-11 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,24 +82,34 @@ files:
68
82
  - README.md
69
83
  - Rakefile
70
84
  - lib/seory.rb
85
+ - lib/seory/condition.rb
86
+ - lib/seory/condition/block.rb
87
+ - lib/seory/condition/build_dsl.rb
88
+ - lib/seory/condition/params.rb
89
+ - lib/seory/condition/path.rb
90
+ - lib/seory/condition/slug.rb
71
91
  - lib/seory/dsl.rb
72
- - lib/seory/page_condition.rb
73
- - lib/seory/page_condition/block_condition.rb
74
- - lib/seory/page_condition/build_dsl.rb
75
- - lib/seory/page_condition/default_condition.rb
76
- - lib/seory/page_condition/params_condition.rb
77
- - lib/seory/page_condition/path_condition.rb
78
- - lib/seory/page_condition/slug_condition.rb
79
- - lib/seory/page_contents.rb
92
+ - lib/seory/dsl/descriptor.rb
93
+ - lib/seory/dsl/page_builder.rb
94
+ - lib/seory/page.rb
95
+ - lib/seory/page_group.rb
96
+ - lib/seory/rails_helper.rb
97
+ - lib/seory/railtie.rb
80
98
  - lib/seory/repository.rb
81
99
  - lib/seory/runtime.rb
82
100
  - lib/seory/version.rb
83
101
  - seory.gemspec
102
+ - spec/seory/condition/path_spec.rb
103
+ - spec/seory/condition/slug_spec.rb
84
104
  - spec/seory/dsl_spec.rb
85
- - spec/seory/page_condition/path_condition_spec.rb
86
- - spec/seory/page_contents_spec.rb
105
+ - spec/seory/page_spec.rb
106
+ - spec/seory/rails_helper_spec.rb
107
+ - spec/seory/repository_spec.rb
87
108
  - spec/seory/runtime_spec.rb
88
109
  - spec/spec_helper.rb
110
+ - spec/support/controller_double.rb
111
+ - spec/support/testing_dsl.rb
112
+ - spec/support/view_context_double.rb
89
113
  homepage: https://github.com/esminc/seory
90
114
  licenses:
91
115
  - MIT
@@ -111,8 +135,14 @@ signing_key:
111
135
  specification_version: 4
112
136
  summary: SEO contents manager for Rails.
113
137
  test_files:
138
+ - spec/seory/condition/path_spec.rb
139
+ - spec/seory/condition/slug_spec.rb
114
140
  - spec/seory/dsl_spec.rb
115
- - spec/seory/page_condition/path_condition_spec.rb
116
- - spec/seory/page_contents_spec.rb
141
+ - spec/seory/page_spec.rb
142
+ - spec/seory/rails_helper_spec.rb
143
+ - spec/seory/repository_spec.rb
117
144
  - spec/seory/runtime_spec.rb
118
145
  - spec/spec_helper.rb
146
+ - spec/support/controller_double.rb
147
+ - spec/support/testing_dsl.rb
148
+ - spec/support/view_context_double.rb
@@ -1,32 +0,0 @@
1
- require 'seory'
2
- require 'seory/page_condition/block_condition'
3
- require 'seory/page_condition/default_condition'
4
- require 'seory/page_condition/params_condition'
5
- require 'seory/page_condition/path_condition'
6
- require 'seory/page_condition/slug_condition'
7
-
8
- module Seory
9
- module PageCondition
10
- class SupposionFailed < Seory::Error; end
11
- extend self
12
-
13
- def [](condition)
14
- if condition == :default
15
- DefaultCondition.new
16
- elsif condition.respond_to?(:match?)
17
- condition
18
- else
19
- suppose(condition)
20
- end
21
- end
22
-
23
- private
24
-
25
- def suppose(condition)
26
- klass = [ParamsCondition, SlugCondition].detect {|klass| klass.supposable?(condition) }
27
- raise SupposionFailed.new(condition.inspect) unless klass
28
-
29
- klass.new(condition)
30
- end
31
- end
32
- end
@@ -1,19 +0,0 @@
1
- require 'seory/page_condition'
2
-
3
- module Seory
4
- module PageCondition
5
- module BuildDsl
6
- def slug(slug)
7
- SlugCondition.new(slug)
8
- end
9
-
10
- def path(path)
11
- PathCondition.new(path)
12
- end
13
-
14
- def params(params)
15
- ParamsCondition.new(params)
16
- end
17
- end
18
- end
19
- end
@@ -1,10 +0,0 @@
1
- module Seory
2
- module PageCondition
3
- class DefaultCondition
4
- def match?(controller)
5
- true
6
- end
7
- end
8
- end
9
- end
10
-
@@ -1,41 +0,0 @@
1
- require 'seory'
2
- require 'seory/page_condition'
3
-
4
- require 'active_support/all'
5
-
6
- module Seory
7
- class EmptyCondition < ::Seory::Error; end
8
-
9
- class PageContents
10
- def initialize(*conditions, &block)
11
- @conditions =
12
- if block_given?
13
- [PageCondition::BlockCondition.new(block)]
14
- else
15
- conditions.map {|condition| Seory::PageCondition[condition] }
16
- end
17
-
18
- raise EmptyCondition if @conditions.blank?
19
-
20
- @contents = {}
21
- end
22
-
23
- def define(name, value = nil, &block)
24
- @contents[name] = block_given? ? block : value
25
- end
26
-
27
- def content_for(name)
28
- @contents[name]
29
- end
30
-
31
- def match?(controller)
32
- return true if default?
33
-
34
- @conditions.any? {|condition| condition.match?(controller) }
35
- end
36
-
37
- def default?
38
- @conditions.all? {|c| c.is_a?(Seory::PageCondition::DefaultCondition) }
39
- end
40
- end
41
- end