sharing_tags 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +19 -0
  4. data/.rspec +4 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +13 -0
  7. data/Guardfile +7 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +112 -0
  10. data/Rakefile +14 -0
  11. data/app/assets/fonts/socicon-webfont.eot +0 -0
  12. data/app/assets/fonts/socicon-webfont.svg +112 -0
  13. data/app/assets/fonts/socicon-webfont.ttf +0 -0
  14. data/app/assets/fonts/socicon-webfont.woff +0 -0
  15. data/app/assets/fonts/socicon-webfont.woff2 +0 -0
  16. data/app/assets/javascripts/sharing_tags/links.js.coffee +11 -0
  17. data/app/assets/javascripts/sharing_tags/share.coffee +48 -0
  18. data/app/views/sharing_tags/_open_graphs.html.slim +21 -0
  19. data/app/views/sharing_tags/_schema_tags.html.slim +8 -0
  20. data/app/views/sharing_tags/_twitter_card.html.slim +20 -0
  21. data/app/views/sharing_tags/meta_tags.html.slim +16 -0
  22. data/bin/rspec +16 -0
  23. data/lib/generators/sharing_tags/install/install_generator.rb +18 -0
  24. data/lib/generators/sharing_tags/install/templates/initializer.rb +18 -0
  25. data/lib/generators/sharing_tags.rb +18 -0
  26. data/lib/sharing_tags/action_controller/filters.rb +13 -0
  27. data/lib/sharing_tags/action_controller/helpers.rb +7 -0
  28. data/lib/sharing_tags/action_view/helpers.rb +57 -0
  29. data/lib/sharing_tags/config.rb +33 -0
  30. data/lib/sharing_tags/configuration.rb +80 -0
  31. data/lib/sharing_tags/context.rb +96 -0
  32. data/lib/sharing_tags/engine.rb +6 -0
  33. data/lib/sharing_tags/network/facebook.rb +14 -0
  34. data/lib/sharing_tags/network.rb +102 -0
  35. data/lib/sharing_tags/railtie.rb +29 -0
  36. data/lib/sharing_tags/version.rb +3 -0
  37. data/lib/sharing_tags.rb +37 -0
  38. data/sharing_tags.gemspec +37 -0
  39. data/spec/controllers/main_controller_spec.rb +105 -0
  40. data/spec/dummy/.gitignore +16 -0
  41. data/spec/dummy/Gemfile +40 -0
  42. data/spec/dummy/Gemfile.lock +125 -0
  43. data/spec/dummy/README.rdoc +28 -0
  44. data/spec/dummy/Rakefile +6 -0
  45. data/spec/dummy/app/assets/images/.keep +0 -0
  46. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  47. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  49. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  50. data/spec/dummy/app/controllers/main_controller.rb +25 -0
  51. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  52. data/spec/dummy/app/mailers/.keep +0 -0
  53. data/spec/dummy/app/models/.keep +0 -0
  54. data/spec/dummy/app/models/concerns/.keep +0 -0
  55. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  56. data/spec/dummy/app/views/main/index.html.slim +16 -0
  57. data/spec/dummy/app/views/main/photo.html.slim +1 -0
  58. data/spec/dummy/app/views/main/profile.html.slim +1 -0
  59. data/spec/dummy/bin/bundle +3 -0
  60. data/spec/dummy/bin/rails +8 -0
  61. data/spec/dummy/bin/rake +8 -0
  62. data/spec/dummy/bin/spring +18 -0
  63. data/spec/dummy/config/application.rb +23 -0
  64. data/spec/dummy/config/boot.rb +4 -0
  65. data/spec/dummy/config/database.yml +25 -0
  66. data/spec/dummy/config/environment.rb +5 -0
  67. data/spec/dummy/config/environments/development.rb +37 -0
  68. data/spec/dummy/config/environments/production.rb +79 -0
  69. data/spec/dummy/config/environments/test.rb +38 -0
  70. data/spec/dummy/config/initializers/assets.rb +8 -0
  71. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  72. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  73. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  74. data/spec/dummy/config/initializers/inflections.rb +16 -0
  75. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  76. data/spec/dummy/config/initializers/session_store.rb +3 -0
  77. data/spec/dummy/config/initializers/sharing_tags.rb +62 -0
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  79. data/spec/dummy/config/locales/en.yml +23 -0
  80. data/spec/dummy/config/routes.rb +61 -0
  81. data/spec/dummy/config/secrets.yml +22 -0
  82. data/spec/dummy/config.ru +4 -0
  83. data/spec/dummy/db/seeds.rb +7 -0
  84. data/spec/dummy/lib/assets/.keep +0 -0
  85. data/spec/dummy/lib/tasks/.keep +0 -0
  86. data/spec/dummy/log/.keep +0 -0
  87. data/spec/dummy/public/404.html +67 -0
  88. data/spec/dummy/public/422.html +67 -0
  89. data/spec/dummy/public/500.html +66 -0
  90. data/spec/dummy/public/favicon.ico +0 -0
  91. data/spec/dummy/public/robots.txt +5 -0
  92. data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
  93. data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
  94. data/spec/generators/install_generator_spec.rb +50 -0
  95. data/spec/helpers/share_link_helper_spec.rb +185 -0
  96. data/spec/models/configuration_spec.rb +180 -0
  97. data/spec/models/context_spec.rb +28 -0
  98. data/spec/models/network_spec.rb +6 -0
  99. data/spec/models/running_in_context_spec.rb +57 -0
  100. data/spec/spec_helper.rb +41 -0
  101. data/spec/support/generator_support.rb +11 -0
  102. data/spec/views/facebook_meta_tags_erb_spec.rb +60 -0
  103. data/spec/views/meta_tags_erb_spec.rb +67 -0
  104. metadata +409 -0
@@ -0,0 +1,185 @@
1
+
2
+ RSpec.describe SharingTags::ActionView::Helpers, :type => :helper do
3
+
4
+ before do
5
+ SharingTags.configure do
6
+ facebook do
7
+ title "fb title"
8
+ description "fb desc"
9
+ share_url "http://c.d"
10
+ page_url "#"
11
+ image "http://img.png"
12
+ end
13
+ end
14
+ end
15
+
16
+ describe "#sharing_tags" do
17
+ pending
18
+ end
19
+
20
+ describe "#render_sharing_tags" do
21
+ before do
22
+ SharingTags.configure do
23
+ title "Sharing title"
24
+ description "Sharing description"
25
+ page_url "http://a.b"
26
+ image "http://img.png"
27
+ end
28
+ end
29
+
30
+ it "generate open graph meta tags" do
31
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:title", content: "Sharing title"}
32
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:description", content: "Sharing description"}
33
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:image", content: "http://img.png"}
34
+ end
35
+
36
+ it "generate schema meta tags" do
37
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "name", content: "Sharing title"}
38
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "description", content: "Sharing description"}
39
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "image", content: "http://img.png"}
40
+ end
41
+
42
+ it "generate twitter card meta tags" do
43
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {name: "twitter:title", content: "Sharing title"}
44
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {name: "twitter:description", content: "Sharing description"}
45
+ end
46
+ end
47
+
48
+ describe "#link_to_facebook_share" do
49
+ before do
50
+ SharingTags.configure do
51
+ facebook do
52
+ title "fb title"
53
+ description "fb desc"
54
+ share_url "http://c.d"
55
+ page_url "http://a.b"
56
+ image "http://img.png"
57
+ end
58
+ end
59
+ end
60
+
61
+ it "generate default text share link" do
62
+ expect(helper.link_to_facebook_share).to have_tag "a", text: "Facebook", with: {href: "http://a.b", role: "sharing_tags_share"}
63
+ expect(helper.link_to_facebook_share).to have_tag "a", with: {"data-share-url" => "http://c.d"}
64
+ expect(helper.link_to_facebook_share).to have_tag "a", without: {"data-share-url" => "http://c.d"}
65
+ expect(helper.link_to_facebook_share).to have_tag("a", without: {
66
+ "data-title" => "fb title",
67
+ "data-description" => "fb desc",
68
+ "data-image" => "http://img.png"
69
+ })
70
+ end
71
+
72
+ it "generate default text sharing link for block" do
73
+ expect(helper.link_to_facebook_share { "Text block" }).to have_tag "a", text: "Text block", with: {href: "http://a.b", role: "sharing_tags_share"}
74
+ end
75
+ end
76
+
77
+ describe "#link_to_vkontakte_share" do
78
+ before do
79
+ SharingTags.configure do
80
+ vkontakte do
81
+ title "vk title"
82
+ description "vk desc"
83
+ share_url "http://vk.share?utm_source=vk"
84
+ page_url "http://vk.share"
85
+ image "http://img.png"
86
+ end
87
+ end
88
+ end
89
+
90
+ it "generate default text share link" do
91
+ expect(helper.link_to_vkontakte_share).to have_tag "a", text: "Vkontakte", with: {href: "http://vk.share", role: "sharing_tags_share"}
92
+ expect(helper.link_to_vkontakte_share).to have_tag("a", with: {
93
+ "data-share-url" => "http://vk.share?utm_source=vk",
94
+ "data-title" => "vk title",
95
+ "data-description" => "vk desc",
96
+ "data-image" => "http://img.png"
97
+ })
98
+ end
99
+
100
+ it "generate default text sharing link for block" do
101
+ expect(helper.link_to_vkontakte_share { "Text block" }).to have_tag "a", text: "Text block", with: {href: "http://vk.share", role: "sharing_tags_share"}
102
+ end
103
+ end
104
+
105
+ describe "#link_to_odnoklassniki_share" do
106
+ before do
107
+ SharingTags.configure do
108
+ odnoklassniki do
109
+ title "od title"
110
+ description "od desc"
111
+ share_url "http://od.share?utm_source=od"
112
+ page_url "http://od.share"
113
+ image "http://img.png"
114
+ end
115
+ end
116
+ end
117
+
118
+
119
+ it "generate default text share link" do
120
+ expect(helper.link_to_odnoklassniki_share).to have_tag "a", text: "Odnoklassniki", with: {href: "http://od.share", role: "sharing_tags_share"}
121
+ expect(helper.link_to_odnoklassniki_share).to have_tag("a", with: {
122
+ "data-share-url" => "http://od.share?utm_source=od",
123
+ "data-title" => "od title",
124
+ "data-description" => "od desc"
125
+ })
126
+ expect(helper.link_to_odnoklassniki_share).to have_tag("a", without: {
127
+ "data-image" => "http://img.png"
128
+ })
129
+ end
130
+
131
+ it "generate default text sharing link for block" do
132
+ expect(helper.link_to_odnoklassniki_share { "Text block" }).to have_tag "a", text: "Text block", with: {href: "http://od.share", role: "sharing_tags_share"}
133
+ end
134
+
135
+ it "generate default text sharing link for block" do
136
+ pending
137
+ expect(
138
+ helper.link_to_odnoklassniki_share(role: "ya-target", data: {target: "main"}) { "Text" }
139
+ ).to have_tag("a", text: "Text block",
140
+ with: {href: "http://od.share", role: "ya-target sharing_tags_share"})
141
+
142
+ expect(helper.link_to_odnoklassniki_share).to have_tag("a", with: {
143
+ "data-share-url" => "http://od.share?utm_source=od",
144
+ "data-title" => "od title",
145
+ "data-description" => "od desc",
146
+ 'data-target' => "main"
147
+ })
148
+ end
149
+
150
+
151
+ end
152
+
153
+ describe "#link_to_twitter_share" do
154
+ before do
155
+ SharingTags.configure do
156
+ twitter do
157
+ link_params utm_source: "tw"
158
+
159
+ title "tw title"
160
+ description "tw desc"
161
+ page_url "http://tw.share"
162
+ image "http://img.png"
163
+ end
164
+ end
165
+ end
166
+
167
+
168
+ it "generate default text share link" do
169
+ expect(helper.link_to_twitter_share).to have_tag "a", text: "Twitter", with: {href: "http://tw.share", role: "sharing_tags_share"}
170
+ expect(helper.link_to_twitter_share).to have_tag("a", with: {
171
+ "data-share-url" => "http://tw.share?utm_source=tw",
172
+ "data-title" => "tw title",
173
+ "data-description" => "tw desc"
174
+ })
175
+ expect(helper.link_to_twitter_share).to have_tag("a", without: {
176
+ "data-image" => "http://img.png"
177
+ })
178
+ end
179
+
180
+ it "generate default text sharing link for block" do
181
+ expect(helper.link_to_twitter_share { "Twitter block" }).to have_tag "a", text: "Twitter block", with: {href: "http://tw.share", role: "sharing_tags_share"}
182
+ end
183
+
184
+ end
185
+ end
@@ -0,0 +1,180 @@
1
+ describe SharingTags::Configuration do
2
+
3
+ after do
4
+ SharingTags.config.clear!
5
+ end
6
+
7
+ subject { SharingTags.config.params }
8
+
9
+ describe "constants" do
10
+
11
+ it "expect NETWORKS" do
12
+ #expect(SharingTags::Configuration).to be_include(:twitter)
13
+ #expect(SharingTags::Configuration).to has_include(:facebook)
14
+ end
15
+
16
+ it "expect defined version" do
17
+ expect(SharingTags::VERSION).to be_truthy
18
+ end
19
+ end
20
+
21
+ describe "define networks in default context" do
22
+ before do
23
+ SharingTags.configure do
24
+ twitter do
25
+ title "Twitter title"
26
+ description { "Twitter description" }
27
+ page_url "http://a.b"
28
+ image "http://img.jpg"
29
+ end
30
+
31
+ facebook do
32
+ title { "Facebook title" }
33
+ share_url { "http://c.d" }
34
+ image { "http://img.png" }
35
+ end
36
+ end
37
+ end
38
+
39
+ subject { SharingTags.config.params }
40
+
41
+ it "expect found twitter" do
42
+ params = subject[:twitter]
43
+ expect(params).to be_truthy
44
+ expect(params[:title]).to be == "Twitter title"
45
+ expect(params[:description]).to be == "Twitter description"
46
+ expect(params[:share_url]).to be == "http://a.b"
47
+ expect(params[:page_url]).to be == "http://a.b"
48
+ expect(params[:image]).to be == "http://img.jpg"
49
+ end
50
+
51
+ it "expect found facebook" do
52
+ params = subject[:facebook]
53
+ expect(params).to be_truthy
54
+ expect(params[:title]).to be == "Facebook title"
55
+ expect(params[:share_url]).to be == "http://c.d"
56
+ expect(params[:image]).to be == "http://img.png"
57
+ end
58
+
59
+ it "not expect found google" do
60
+ expect(subject.google).to be_blank
61
+ end
62
+
63
+ end
64
+
65
+ describe "create new context" do
66
+ before do
67
+ SharingTags.configure do
68
+ context :photo do
69
+ google do
70
+ title "Photo title"
71
+ description { "Photo description" }
72
+ share_url { |p1, p2| "http://#{p1}.#{p2}/" }
73
+ image "http://img.jpg"
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ subject { SharingTags.config.params }
80
+
81
+ it "expect not found default" do
82
+ expect(subject.google).to be_blank
83
+ expect(subject.facebook).to be_blank
84
+ expect(subject.twitter).to be_blank
85
+ end
86
+
87
+ describe "switch context to photo" do
88
+ before do
89
+ SharingTags.config.switch_context(:photo, "param1", "param2")
90
+ end
91
+
92
+ it "expect new context data" do
93
+ expect(subject[:google][:title]).to be == "Photo title"
94
+ expect(subject[:google][:description]).to be == "Photo description"
95
+ expect(subject[:google][:share_url]).to be == "http://param1.param2/"
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "define utm params" do
101
+ before do
102
+ SharingTags.configure do
103
+ share_url "http:://example.com"
104
+
105
+ google do
106
+ link_params utm_source: "google_source", utm_medium: "google_medium", utm_content: "google_content",
107
+ utm_campaign: "google_campaign", marker: "google_marker"
108
+ end
109
+
110
+ facebook do
111
+ link_params utm_source: "facebook_source", utm_medium: "facebook_medium", utm_content: "facebook_content",
112
+ utm_campaign: "facebook_campaign", marker: "facebook_marker"
113
+ end
114
+
115
+ twitter do
116
+ share_url "http:://for_twitter.com"
117
+
118
+ link_params utm_source: "twitter_source", utm_medium: "twitter_medium"
119
+ end
120
+ end
121
+ end
122
+
123
+ it "expect add utm params to facebook share_url" do
124
+ facebook_config = subject.facebook
125
+ expect(facebook_config).to be_truthy
126
+ expect(facebook_config.share_url).to be_include("http:://example.com")
127
+ expect(facebook_config.share_url).to be_include("utm_campaign=facebook_campaign")
128
+ expect(facebook_config.share_url).to be_include("utm_source=facebook_source")
129
+ expect(facebook_config.share_url).to be_include("marker=facebook_marker")
130
+
131
+ expect(facebook_config.share_url).to_not be_include("utm_source=google_source")
132
+ expect(facebook_config.share_url).to_not be_include("utm_source=twitter_source")
133
+ end
134
+
135
+ it "expect add utm params to google share_url" do
136
+ google_config = subject.google
137
+ expect(google_config).to be_truthy
138
+ expect(google_config.share_url).to be_include("http:://example.com")
139
+ expect(google_config.share_url).to be_include("utm_campaign=google_campaign")
140
+ expect(google_config.share_url).to be_include("utm_source=google_source")
141
+
142
+ expect(google_config.share_url).to_not be_include("utm_campaign=facebook_campaign")
143
+ expect(google_config.share_url).to_not be_include("utm_source=facebook_source")
144
+ expect(google_config.share_url).to_not be_include("utm_source=twitter_source")
145
+
146
+ end
147
+
148
+ it "expect add utm params to twitter share_url" do
149
+ twitter_config = subject.twitter
150
+ expect(twitter_config).to be_truthy
151
+ expect(twitter_config.share_url).to be_include("http:://for_twitter.com")
152
+ expect(twitter_config.share_url).to be_include("utm_source=twitter_source")
153
+ expect(twitter_config.share_url).to be_include("utm_medium=twitter_medium")
154
+
155
+ expect(twitter_config.share_url).to_not be_include("utm_campaign")
156
+ expect(twitter_config.share_url).to_not be_include("utm_source=google_source")
157
+ expect(twitter_config.share_url).to_not be_include("utm_source=facebook_source")
158
+ expect(twitter_config.share_url).to_not be_include("marker")
159
+ end
160
+ end
161
+
162
+ describe "custom tags for networks" do
163
+ before do
164
+ SharingTags.configure do
165
+ facebook do
166
+ app_id "APP ID"
167
+ end
168
+ end
169
+ end
170
+
171
+ describe "switch context to photo" do
172
+
173
+ it "expect new context data" do
174
+ expect(subject[:facebook][:app_id]).to be == "APP ID"
175
+ end
176
+ end
177
+ end
178
+
179
+
180
+ end
@@ -0,0 +1,28 @@
1
+ describe SharingTags::Context do
2
+
3
+ before do
4
+ SharingTags.configure do
5
+ twitter do
6
+ title "Twitter title"
7
+ end
8
+
9
+ facebook do
10
+ title "Facebook title"
11
+ end
12
+ end
13
+ end
14
+
15
+ let(:config) { SharingTags.config }
16
+
17
+ describe "method missing" do
18
+ let(:context) { SharingTags::Context.new(:foo, config) }
19
+
20
+ it "expect save network attributes to default network" do
21
+ expect { context.title "some title" }.to change { context.default_network.attributes[:title] }
22
+ end
23
+
24
+ it "expect raise error when try define unavailable network attribute" do
25
+ expect { context.summary = "title" }.to raise_error(SharingTags::Network::Error)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ describe SharingTags::Network do
2
+
3
+ it "expect get's list of available networks" do
4
+ expect(SharingTags::Network.lists).to include(:facebook, :twitter, :google, :vkontakte)
5
+ end
6
+ end
@@ -0,0 +1,57 @@
1
+ describe SharingTags::Configuration do
2
+ before do
3
+ SharingTags.configure do
4
+ page_url { root_url }
5
+
6
+ twitter do
7
+ title { awesome_title }
8
+ end
9
+
10
+ context :copyright do
11
+ twitter do
12
+ title { |band| "#{awesome_title} (c) #{band}" }
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ let(:running_context) do
19
+ Class.new do
20
+ def root_url
21
+ "context url"
22
+ end
23
+
24
+ def awesome_title
25
+ "All you need is love"
26
+ end
27
+ end
28
+ end
29
+
30
+ let(:params) { SharingTags.config.within_context_params(running_context.new) }
31
+
32
+ describe "default context" do
33
+ it "expect get twitter title from calling in running_context" do
34
+ expect(params.twitter.page_url).to eql("context url")
35
+ end
36
+
37
+ it "expect get page_url from calling in running_context" do
38
+ expect(params.twitter.title).to eql("All you need is love")
39
+ end
40
+ end
41
+
42
+ describe "copyright context" do
43
+ before do
44
+ SharingTags.config.switch_context(:copyright, "Beatles")
45
+ end
46
+
47
+ it "expect get page_url from calling in running_context" do
48
+ expect(params.twitter.title).to eql("All you need is love (c) Beatles")
49
+ end
50
+
51
+ it "expect get twitter title from calling in running_context" do
52
+ expect(params.twitter.page_url).to eql("context url")
53
+ end
54
+ end
55
+
56
+
57
+ end
@@ -0,0 +1,41 @@
1
+ Dir.chdir(File.expand_path("../dummy", __FILE__)) { require File.expand_path("config/environment") }
2
+
3
+ require 'rspec/rails'
4
+ require 'pry'
5
+ require 'rspec-html-matchers'
6
+ require 'ammeter/init'
7
+ require 'slim'
8
+ require 'rspec/support/spec'
9
+
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ if ENV['CODECLIMATE_REPO_TOKEN']
13
+ require 'codeclimate-test-reporter'
14
+ CodeClimate::TestReporter.configuration.git_dir = "."
15
+ CodeClimate::TestReporter.start
16
+ end
17
+
18
+ require 'coveralls'
19
+ Coveralls.wear!
20
+
21
+ RSpec.configure do |config|
22
+ config.include RSpecHtmlMatchers
23
+ config.include GeneratorSupport, type: :generator
24
+
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # config.profile_examples = 10
29
+ config.order = :random
30
+ Kernel.srand config.seed
31
+
32
+ config.expect_with :rspec do |expectations|
33
+ expectations.syntax = :expect
34
+ end
35
+
36
+ config.mock_with :rspec do |mocks|
37
+ mocks.syntax = :expect
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ end
@@ -0,0 +1,11 @@
1
+ module GeneratorSupport
2
+
3
+ def cleanup_destination_root
4
+ FileUtils.rm_rf destination_root
5
+ end
6
+
7
+ def content_for(file_name)
8
+ File.read(file(file_name))
9
+ end
10
+
11
+ end
@@ -0,0 +1,60 @@
1
+
2
+ RSpec.describe "sharing_tags/meta_tags", :type => :view do
3
+
4
+ context "constant params" do
5
+ before do
6
+ controller.append_view_path 'app/views'
7
+
8
+ SharingTags.configure do
9
+ share_url "http:://dummy.com"
10
+
11
+ facebook do
12
+ title "Facebook title"
13
+ description "Facebook description"
14
+ page_url "http://a.b"
15
+ image_url "http://img.jpg", "100x200", "image/jpeg"
16
+ end
17
+ end
18
+ end
19
+
20
+ it "render image size tags" do
21
+ render
22
+ expect(rendered).to have_tag "meta", with: {property: "og:title", content: "Facebook title"}
23
+ expect(rendered).to have_tag "meta", with: {property: "og:description", content: "Facebook description"}
24
+ expect(rendered).to have_tag "meta", with: {property: "og:image", content: "http://img.jpg"}
25
+ expect(rendered).to have_tag "meta", with: {property: "og:image:type", content: "image/jpeg"}
26
+ expect(rendered).to have_tag "meta", with: {property: "og:image:width", content: "100"}
27
+ expect(rendered).to have_tag "meta", with: {property: "og:image:height",content: "200"}
28
+ expect(rendered).to have_tag "meta", with: {property: "og:url", content: "http://a.b"}
29
+ end
30
+ end
31
+
32
+ context "constant params" do
33
+ before do
34
+ controller.append_view_path 'app/views'
35
+
36
+ SharingTags.configure do
37
+ share_url "http:://dummy.com"
38
+
39
+ facebook do
40
+ title { "Facebook title" }
41
+ description { "Facebook description" }
42
+ page_url { "http://a.b" }
43
+ image_url("100x200", "image/jpeg") { "http://img.jpg" }
44
+ end
45
+ end
46
+ end
47
+
48
+ it "render image size tags" do
49
+ render
50
+ expect(rendered).to have_tag "meta", with: {property: "og:title", content: "Facebook title"}
51
+ expect(rendered).to have_tag "meta", with: {property: "og:description", content: "Facebook description"}
52
+ expect(rendered).to have_tag "meta", with: {property: "og:image", content: "http://img.jpg"}
53
+ expect(rendered).to have_tag "meta", with: {property: "og:image:type", content: "image/jpeg"}
54
+ expect(rendered).to have_tag "meta", with: {property: "og:image:width", content: "100"}
55
+ expect(rendered).to have_tag "meta", with: {property: "og:image:height",content: "200"}
56
+ expect(rendered).to have_tag "meta", with: {property: "og:url", content: "http://a.b"}
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,67 @@
1
+ RSpec.describe "sharing_tags/meta_tags", :type => :view do
2
+
3
+ before do
4
+ controller.append_view_path 'app/views'
5
+
6
+ SharingTags.configure do
7
+ share_url "http:://dummy.com"
8
+
9
+ facebook do
10
+ title "Facebook title"
11
+ description "Facebook description"
12
+ page_url "http://a.b"
13
+ image_url "http://img.jpg"
14
+ end
15
+
16
+ google do
17
+ title "Google title"
18
+ description "Google description"
19
+ page_url "http://c.d"
20
+ image_url "http://img.png"
21
+ end
22
+
23
+ twitter do
24
+ title "Twitter title"
25
+ description "Twitter description"
26
+ end
27
+ end
28
+ end
29
+
30
+ let(:config) { SharingTags.config }
31
+
32
+ it "render open graph tags for Facebook" do
33
+ render
34
+ expect(rendered).to have_tag "meta", with: {property: "og:title", content: "Facebook title"}
35
+ expect(rendered).to have_tag "meta", with: {property: "og:description", content: "Facebook description"}
36
+ expect(rendered).to have_tag "meta", with: {property: "og:image", content: "http://img.jpg"}
37
+ expect(rendered).to have_tag "meta", with: {property: "og:url", content: "http://a.b"}
38
+ end
39
+
40
+ it "render schema tags for Google+" do
41
+ render
42
+
43
+ expect(rendered).to have_tag "meta", with: {itemprop: "name", content: "Google title"}
44
+ expect(rendered).to have_tag "meta", with: {itemprop: "description", content: "Google description"}
45
+ expect(rendered).to have_tag "meta", with: {itemprop: "image", content: "http://img.png"}
46
+ end
47
+
48
+ it "render twitter card tags" do
49
+ render
50
+
51
+ expect(rendered).to have_tag "meta", with: {name: "twitter:card", content: "summary"}
52
+ # expect(rendered).to have_tag "meta", with: {name: "twitter:site", content: ""}
53
+ expect(rendered).to have_tag "meta", with: {name: "twitter:title", content: "Twitter title"}
54
+ expect(rendered).to have_tag "meta", with: {name: "twitter:description",content: "Twitter description"}
55
+ # expect(rendered).to have_tag "meta", with: {name: "twitter:creator", content: ""}
56
+ # expect(rendered).to have_tag "meta", with: {name: "twitter:image:src", content: ""}
57
+ # expect(rendered).to have_tag "meta", with: {name: "twitter:domain", content: ""}
58
+ end
59
+
60
+ it "expect render nothing with clear config" do
61
+ config.clear!
62
+ render
63
+ expect(rendered).to_not have_tag('meta')
64
+ end
65
+
66
+
67
+ end