ruby-wordpress 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70e9d73a18077c70dd4974d042ecc80a068a97d4
4
- data.tar.gz: fc64bc3a3c5e0d77a861c5c0180a4c76f58e973a
3
+ metadata.gz: 45c42701a1b62179287d6043b6668b493998db65
4
+ data.tar.gz: 3853591884393aed29c2f8b7a13b453ebdd22a15
5
5
  SHA512:
6
- metadata.gz: fbeae0d88a1d4701ba0dcce78111342f674a673f4c14f40437e25b78fe3c38f80005465f83badb7721637cefc11cba0956cbc78b3d9405b9e69b14b7f80ce693
7
- data.tar.gz: e54c1d9e11a1e3f421412a743d685084f48f602e0c9ecbaf5b4ff3195b950e67b62009ca98bf368ed10906a9ca47e0b6ffcdd5ae4c1f88f68b6d9f71a8135105
6
+ metadata.gz: 5c0c096ab6db373b64a27423d52a8e2b3511a2a59b95d08e9568f80a2ce1f27903743f4a8e2e9b395f3dcafb98d51a5e0ece9abc73184166bf6fae1c9f78d41a
7
+ data.tar.gz: be07e409b51cf877317cec0b0cf358ff24c6a307a61bf048bd4b72c2f1cc5b2c6c142a752712edb2797ecc07f94f929a2462204738450fb7549ba444a65e2a56
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .DS_*
19
+ /test_configuration.yml
20
+ .rspec
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ before_script:
2
+ - mysql -e 'CREATE DATABASE `ruby-wordpress-test`'
3
+ - cp test_configuration.example.yml test_configuration.yml
4
+ language: ruby
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - rbx-19mode
9
+ - rbx-18mode
10
+ - 1.8.7
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # Ruby/WordPress
2
2
 
3
+ [![Build Status](https://travis-ci.org/keichan34/ruby-wordpress.png?branch=master)](https://travis-ci.org/keichan34/ruby-wordpress)
4
+
3
5
  Access your WordPress database with Ruby.
4
6
 
7
+ Read more: [http://keita.flagship.cc/2013/06/ruby-wordpress/](http://keita.flagship.cc/2013/06/ruby-wordpress/)
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -30,15 +34,47 @@ See the [mysql2 connection options](https://github.com/brianmario/mysql2#connect
30
34
  Additional options:
31
35
 
32
36
  * `:wordpress_prefix` (default: 'wp_')
37
+ * `:wordpress_wp_content` (used for uploading attachments)
33
38
 
34
39
  ## Changelog
35
40
 
41
+ ### 0.0.3
42
+
43
+ Bug fixes
44
+
45
+ * `WordPress::Post#set_post_terms` will now respect the `append` parameter, when true.
46
+ * `WordPress::Post#set_post_terms` now accepts an empty array as the `terms` argument.
47
+ * `WordPress#query` `:meta_query` now correctly queries for multiple meta query statements. Only `AND` is supported at this point.
48
+ * `WordPress#query` `:meta_query` `:type` is now respected correctly
49
+ * `WordPress#query` `:meta_query` `BETWEEN`, `NOT BETWEEN`, `IN`, `NOT IN` works as expected.
50
+
51
+ New features
52
+
53
+ * PHP serialization for Ruby arrays and hashes in `WordPress::Options`
54
+ * 1.8.7 syntax support
55
+ * Added `WordPress::Post#==`. Comparison is performed only with IDs now.
56
+
57
+ ### 0.0.2
58
+
59
+ * Bug fixes
60
+ * Post meta
61
+ * Taxonomy functions
62
+ * Adds post meta queries
63
+
36
64
  ### 0.0.1
37
65
 
38
66
  * Initial public release
39
67
  * Basic SQL functions (WordPress::Base)
40
68
  * `wp_options` accessor
41
69
 
70
+ ## Hacking
71
+
72
+ Hack away! Just make sure you have your `test_configuration.yml` file set up correctly. There's an example in `test_configuration.example.yml`; you can copy this and tailor it to your environment.
73
+
74
+ Please do not use a real database for testing - it is wiped clean before the suite runs, and loads the attached WordPress default schema.
75
+
76
+ The default `rake` task will run the entire test suite.
77
+
42
78
  ## Contributing
43
79
 
44
80
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/lib/wordpress.rb CHANGED
@@ -17,17 +17,17 @@ class WordPress
17
17
 
18
18
  options[:wordpress_prefix] ||= 'wp_'
19
19
  @tbl = {
20
- terms: options[:wordpress_prefix] + 'terms',
21
- termtax: options[:wordpress_prefix] + 'term_taxonomy',
22
- termrel: options[:wordpress_prefix] + 'term_relationships',
23
- posts: options[:wordpress_prefix] + 'posts',
24
- postmeta: options[:wordpress_prefix] + 'postmeta',
25
- options: options[:wordpress_prefix] + 'options',
26
- prefix: options[:wordpress_prefix]
20
+ :terms => options[:wordpress_prefix] + 'terms',
21
+ :termtax => options[:wordpress_prefix] + 'term_taxonomy',
22
+ :termrel => options[:wordpress_prefix] + 'term_relationships',
23
+ :posts => options[:wordpress_prefix] + 'posts',
24
+ :postmeta => options[:wordpress_prefix] + 'postmeta',
25
+ :options => options[:wordpress_prefix] + 'options',
26
+ :prefix => options[:wordpress_prefix]
27
27
  }
28
28
 
29
29
  @conn = Mysql2::Client.new options
30
- @conn.query_options.merge!(symbolize_keys: true)
30
+ @conn.query_options.merge!(:symbolize_keys => true)
31
31
 
32
32
  @configuration = options
33
33
 
@@ -49,8 +49,8 @@ class WordPress
49
49
 
50
50
  # Defaults
51
51
  args = {
52
- post_type: 'post',
53
- post_status: 'publish'
52
+ :post_type => 'post',
53
+ :post_status => 'publish'
54
54
  }.merge(args)
55
55
 
56
56
  wheres_and = []
@@ -103,23 +103,51 @@ class WordPress
103
103
  # Meta finders
104
104
 
105
105
  if (mqs = args[:meta_query]) and mqs.kind_of?(Array)
106
- inner_joins << "`#{@tbl[:postmeta]}` ON `#{@tbl[:posts]}`.`ID`=`#{@tbl[:postmeta]}`.`post_id`"
107
- mqs.each do |mq|
106
+ append = (args[:meta_query_relation] || '').upcase == 'OR' ? (meta_ors = []) : wheres_and
107
+
108
+ mqs.each_with_index do |mq, i|
109
+ postmeta_alias = "pm_#{i}"
110
+ inner_joins << "`#{@tbl[:postmeta]}` AS `#{postmeta_alias}` ON `#{@tbl[:posts]}`.`ID`=`#{postmeta_alias}`.`post_id`"
108
111
  mq_params = {
109
- compare: '=',
110
- type: 'CHAR' # Ignored for now
112
+ :compare => '=',
113
+ :type => 'CHAR' # Ignored for now
111
114
  }.merge(mq)
112
115
 
113
116
  # Allowed compares
114
- mq_params[:compare] = '=' unless ['=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'].include?(mq_params[:compare])
117
+ mq_params[:compare] = '=' unless ['=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'].include?(mq_params[:compare].upcase)
118
+
119
+ # Allowed types
120
+ mq_params[:type] = 'CHAR' unless ['NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'].include?(mq_params[:type].upcase)
121
+
122
+ mq_params[:type] = 'SIGNED' if mq_params[:type] == 'NUMERIC'
123
+
124
+ if mq_params[:compare] =~ /BETWEEN/
125
+ # Meta value needs to be a 2-element array or range
126
+ x = mq_params[:value]
127
+ raise ArgumentError.new("#{mq_params[:compare]} requires an Array with 2 elements or a Range. You passed #{x.class.to_s}.") if !(x.kind_of?(Array) and x.count == 2) and !x.kind_of?(Range)
128
+ mq_params[:type] = 'SIGNED' if !mq[:type] and x.first.kind_of?(Integer) and x.last.kind_of?(Integer)
129
+ mq_params[:type] = 'DECIMAL' if !mq[:type] and x.first.kind_of?(Float) and x.last.kind_of?(Float)
130
+ comparator = "'#{@conn.escape x.first.to_s}' AND '#{@conn.escape x.last.to_s}'"
131
+ elsif mq_params[:compare] =~ /IN/
132
+ x = mq_params[:value]
133
+ raise ArgumentError.new("#{mq_params[:compare]} requires an Array or a Range.") if !x.kind_of?(Array) and !x.kind_of?(Range)
134
+ mq_params[:type] = 'SIGNED' if !mq[:type] and x.first.kind_of?(Integer) and x.last.kind_of?(Integer)
135
+ mq_params[:type] = 'DECIMAL' if !mq[:type] and x.first.kind_of?(Float) and x.last.kind_of?(Float)
136
+ comparator = '(' + x.map { |e| "'#{ @conn.escape e.to_s }'" }.join(', ') + ')'
137
+ else
138
+ comparator = "'" + @conn.escape(mq_params[:value].to_s) + "'"
139
+ end
115
140
 
116
- wheres_and << "(`#{@tbl[:postmeta]}`.`meta_key`='#{@conn.escape mq_params[:key].to_s}' AND `#{@tbl[:postmeta]}`.`meta_value`='#{@conn.escape mq_params[:value].to_s}')"
141
+ append << "(`#{postmeta_alias}`.`meta_key`='#{@conn.escape mq_params[:key].to_s}' AND CAST(`#{postmeta_alias}`.`meta_value` AS #{mq_params[:type]}) #{mq_params[:compare]} #{ comparator })"
117
142
  end
143
+
144
+ wheres_and << meta_ors.join(' OR ') if (args[:meta_query_relation] || '').upcase == 'OR'
145
+
118
146
  end
119
147
 
120
148
  query = "SELECT `#{@tbl[:posts]}`.* FROM `#{@tbl[:posts]}` "
121
149
  if inner_joins.length > 0
122
- query += "INNER JOIN #{inner_joins.join ', '} "
150
+ query += inner_joins.map { |e| "INNER JOIN #{e}" }.join(' ') + ' '
123
151
  end
124
152
 
125
153
  query += "WHERE #{ wheres_and.join ' AND ' }"
@@ -1,6 +1,6 @@
1
1
  # Encoding: UTF-8
2
2
 
3
- require 'unicode_utils/nfc'
3
+ require 'unicode_utils/nfc' unless RUBY_VERSION =~ /1\.8\.7/
4
4
 
5
5
  class WordPress::Base
6
6
  def initialize root
@@ -61,9 +61,9 @@ class WordPress::Base
61
61
 
62
62
  def set_post_meta(id, meta_key, meta_value)
63
63
  update_or_insert $tbl[:postmeta], "`post_id`='#{id.to_i}' AND `meta_key`='#{@conn.escape meta_key.to_s}'", {
64
- post_id: id,
65
- meta_key: meta_key.to_s,
66
- meta_value: meta_value.to_s
64
+ :post_id => id,
65
+ :meta_key => meta_key.to_s,
66
+ :meta_value => meta_value.to_s
67
67
  }
68
68
  end
69
69
 
@@ -75,7 +75,17 @@ class WordPress::Base
75
75
  def set_post_terms(post_id, terms, taxonomy, append=false)
76
76
  terms_esc = terms.map { |e| "'#{@conn.escape e.to_s}'" }
77
77
  terms_slugs = terms.map { |e| "'#{@conn.escape(CGI::escape e.to_s)}'"}
78
- raise ArgumentError, 'Terms must be an array with more than zero elements' unless terms_esc.count > 0
78
+
79
+ if terms_esc.count == 0 and !append
80
+ # Overwrite with nothing.
81
+ @conn.query("DELETE `#{@tbl[:termrel]}` FROM `#{@tbl[:termrel]}` JOIN `#{@tbl[:termtax]}` ON `#{@tbl[:termrel]}`.`term_taxonomy_id`=`#{@tbl[:termtax]}`.`term_taxonomy_id` WHERE `#{@tbl[:termtax]}`.`taxonomy`='#{@conn.escape taxonomy}' AND `#{@tbl[:termrel]}`.`object_id` = '#{post_id.to_i}'")
82
+
83
+ return
84
+ elsif terms_esc.count == 0 and append
85
+ # Because we want to append nothing, there's no harm done with just returning here.
86
+ return
87
+ end
88
+
79
89
  # Cache post terms and term IDs
80
90
  termtax_rel = Hash[@conn.query("SELECT `#{@tbl[:termtax]}`.`term_taxonomy_id`, `#{@tbl[:terms]}`.`name` FROM `#{@tbl[:terms]}`, `#{@tbl[:termtax]}` WHERE (`#{@tbl[:terms]}`.`name` IN (#{ terms_esc.join ', ' }) OR `#{@tbl[:terms]}`.`slug` IN (#{ terms_slugs.join ', ' })) AND `#{@tbl[:terms]}`.`term_id` = `#{@tbl[:termtax]}`.`term_id` AND `#{@tbl[:termtax]}`.`taxonomy` = '#{@conn.escape taxonomy}' GROUP BY `#{@tbl[:terms]}`.`name`").map { |e| [e[:name], e[:term_taxonomy_id]] }]
81
91
 
@@ -1,19 +1,32 @@
1
1
  # Encoding: UTF-8
2
2
 
3
+ require 'php_serialize'
4
+
3
5
  class WordPress::Options < WordPress::Base
4
6
  def [](key)
5
7
  v = nil
6
8
  @conn.query("SELECT `option_value` FROM `#{@tbl[:options]}` WHERE `option_name`='#{@conn.escape key}' LIMIT 1").each do |row|
7
9
  v = row[:option_value]
8
10
  end
11
+ # Apply out-filters
12
+ if v
13
+ if v[0, 1] == 'a' and v[-1, 1] == '}'
14
+ # PHP-serialized array
15
+ v = PHP.unserialize v
16
+ end
17
+ end
9
18
  v
10
19
  end
11
20
 
12
21
  def []=(key, value)
13
- old_value = nil
14
- @conn.query("SELECT `option_value` FROM `#{@tbl[:options]}` WHERE `option_name`='#{@conn.escape key}' LIMIT 1").each do |row|
15
- old_value = row[:option_value]
22
+ # Apply in-filters
23
+
24
+ if value.kind_of?(Hash) or value.kind_of?(Array)
25
+ value = PHP.serialize value
16
26
  end
27
+
28
+ old_value = self[key]
29
+
17
30
  if !value.nil? and !old_value.nil? and value != old_value
18
31
  # Update operation.
19
32
  @conn.query("UPDATE `#{@tbl[:options]}` SET `option_value`='#{@conn.escape value}' WHERE `option_name`='#{@conn.escape key}'")
@@ -110,7 +110,7 @@ class WordPress::Post < WordPress::Base
110
110
  terms = [terms] unless terms.kind_of?(Array)
111
111
  current_terms = get_the_terms(taxonomy)
112
112
  return current_terms if current_terms.sort == terms.sort && append == false
113
- super @post_id, terms, taxonomy, append=false
113
+ super @post_id, terms, taxonomy, append
114
114
  end
115
115
 
116
116
  # Attachments
@@ -168,13 +168,13 @@ class WordPress::Post < WordPress::Base
168
168
  out.close
169
169
 
170
170
  attachment = self.class.build @wp, {
171
- post_title: title,
172
- post_name: CGI::escape(title.downcase),
173
- post_status: 'inherit',
174
- post_parent: @post_id,
175
- post_type: 'attachment',
176
- post_mime_type: mimetype,
177
- guid: uri_basename + '/' + relative_filepath + ext
171
+ :post_title => title,
172
+ :post_name => CGI::escape(title.downcase),
173
+ :post_status => 'inherit',
174
+ :post_parent => @post_id,
175
+ :post_type => 'attachment',
176
+ :post_mime_type => mimetype,
177
+ :guid => uri_basename + '/' + relative_filepath + ext
178
178
  }
179
179
  attachment.save
180
180
 
@@ -191,28 +191,28 @@ class WordPress::Post < WordPress::Base
191
191
  thumb_img.write File.join(file_basename, "#{'%02d' % today.year}/#{'%02d' % today.month}/#{thumbnail_filename}")
192
192
 
193
193
  size_hash[:thumbnail] = {
194
- file: thumbnail_filename,
195
- width: 150,
196
- height: 150
194
+ :file => thumbnail_filename,
195
+ :width => 150,
196
+ :height => 150
197
197
  }
198
198
 
199
199
  size_hash[:medium] = {
200
- file: title + ext,
201
- height: img.rows,
202
- width: img.columns
200
+ :file => title + ext,
201
+ :height => img.rows,
202
+ :width => img.columns
203
203
  }
204
204
 
205
205
  size_hash[:large] = {
206
- file: title + ext,
207
- height: img.rows,
208
- width: img.columns
206
+ :file => title + ext,
207
+ :height => img.rows,
208
+ :width => img.columns
209
209
  }
210
210
 
211
211
  attachment.post_meta['_wp_attachment_metadata'] = {
212
- file: title + ext,
213
- height: img.rows,
214
- width: img.columns,
215
- sizes: size_hash
212
+ :file => title + ext,
213
+ :height => img.rows,
214
+ :width => img.columns,
215
+ :sizes => size_hash
216
216
  }
217
217
  rescue Exception => e
218
218
  # raise e
@@ -224,12 +224,12 @@ class WordPress::Post < WordPress::Base
224
224
 
225
225
  def featured_image
226
226
  thumb_id = post_meta['_thumbnail_id']
227
- @wp.query(post_type: 'attachment', post_parent: @post_id, post_status: 'inherit', p: thumb_id).first if thumb_id
227
+ @wp.query(:post_type => 'attachment', :post_parent => @post_id, :post_status => 'inherit', :p => thumb_id).first if thumb_id
228
228
  end
229
229
 
230
230
  def attached_files *args
231
231
  attach_args = {
232
- post_type: 'attachment', post_parent: @post_id, post_status: 'inherit'
232
+ :post_type => 'attachment', :post_parent => @post_id, :post_status => 'inherit'
233
233
  }.merge(args[0] || {})
234
234
  @wp.query attach_args
235
235
  end
@@ -263,4 +263,14 @@ class WordPress::Post < WordPress::Base
263
263
  post
264
264
  end
265
265
 
266
+ # Equality
267
+
268
+ def == other
269
+ other.post_id == post_id ? true : false
270
+ end
271
+
272
+ def <=> other
273
+ post_id <=> other.post_id
274
+ end
275
+
266
276
  end
@@ -16,7 +16,7 @@ class WordPress::Post::Meta < WordPress::Base
16
16
  end
17
17
  # Apply out-filters
18
18
  if v
19
- if v[0] == 'a' and v[-1] == '}'
19
+ if v[0, 1] == 'a' and v[-1, 1] == '}'
20
20
  # PHP-serialized array
21
21
  v = PHP.unserialize v
22
22
  end
@@ -0,0 +1,33 @@
1
+ # Encoding: UTF-8
2
+
3
+ class WordPress::Schema < WordPress::Base
4
+
5
+ # Initialize the database. Will drop your current database!
6
+ def initialize!
7
+ drop!
8
+ create_db!
9
+ load!
10
+ end
11
+
12
+ def load!
13
+ @conn.query_options[:flags] = Mysql2::Client::MULTI_STATEMENTS
14
+
15
+ schema = File.open(File.join(File.dirname(__FILE__), '..', '..', 'wordpress-3.5.1.sql')).read
16
+ @conn.query(schema)
17
+ end
18
+
19
+ private
20
+
21
+ def drop!
22
+ # Drops the database
23
+ db = @wp.configuration[:database]
24
+ @conn.query "DROP DATABASE `#{db}`"
25
+ end
26
+
27
+ def create_db!
28
+ db = @wp.configuration[:database]
29
+ @conn.query "CREATE DATABASE `#{db}`"
30
+ @conn.query "USE `#{db}`"
31
+ end
32
+
33
+ end
@@ -1,5 +1,5 @@
1
1
  class WordPress
2
2
  module Version
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -19,11 +19,15 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "mysql2", "~> 0.3.11"
22
- spec.add_dependency "unicode_utils", "~> 1.4.0"
22
+
23
+ spec.add_dependency "unicode_utils", "~> 1.4.0" unless RUBY_VERSION =~ /1\.8\.7/
24
+
23
25
  spec.add_dependency "k-php-serialize", "~> 1.2.0"
24
26
  spec.add_dependency "mime-types", "~> 1.23"
25
27
  spec.add_dependency 'rmagick', '= 2.13.2'
26
28
 
27
29
  spec.add_development_dependency "bundler", "~> 1.3"
28
30
  spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency "pry"
29
33
  end
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'wordpress'
5
+
6
+ require 'wordpress/schema'
7
+
8
+ require 'yaml'
9
+
10
+ require 'pry'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+
23
+ # Set up the WordPress schema
24
+
25
+ config.before(:suite) do
26
+ $wp_conf = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', 'test_configuration.yml')))
27
+ multistatement_conf = $wp_conf.merge({ :flags => Mysql2::Client::MULTI_STATEMENTS })
28
+ schema = WordPress::Schema.new(WordPress.new multistatement_conf)
29
+ schema.initialize!
30
+ # Give MySQL time, folks...
31
+ sleep 2
32
+
33
+ $wp = WordPress.new $wp_conf
34
+ end
35
+
36
+ config.after(:suite) do
37
+ # We probably should be wiping the database clean at this point, but we'll restrain from doing that for now.
38
+ end
39
+
40
+ config.before(:each) do
41
+ $wp.conn.query("START TRANSACTION")
42
+ end
43
+
44
+ config.after(:each) do
45
+ $wp.conn.query("ROLLBACK")
46
+ end
47
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordPress::Options do
4
+
5
+ subject do
6
+ $wp.options
7
+ end
8
+
9
+ it "should be the correct class" do
10
+ subject.class.should == WordPress::Options
11
+ end
12
+
13
+ it "should store a value" do
14
+ subject['hello'] = 'there'
15
+ subject['hello'].should == 'there'
16
+ end
17
+
18
+ it "should have the correct inital DB version" do
19
+ subject['initial_db_version'].should == '22441'
20
+ end
21
+
22
+ it "should correctly handle an array" do
23
+ the_array = [ 1, 2, 'hello' ]
24
+ subject['hello'] = the_array
25
+ subject['hello'].should == the_array
26
+ end
27
+
28
+ it "should correctly handle a hash" do
29
+ the_hash = { 'hello' => 'world', 'goodbye' => 'moon' }
30
+ subject['hello'] = the_hash
31
+ subject['hello'].should == the_hash
32
+ end
33
+
34
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordPress::Post do
4
+
5
+ subject { $wp.new_post({ :post_title => 'Sample Post', :post_name => 'sample-post-name' }) }
6
+
7
+ its :class do
8
+ should be WordPress::Post
9
+ end
10
+
11
+ its :post_title do
12
+ should eq 'Sample Post'
13
+ end
14
+
15
+ its :post_name do
16
+ should eq 'sample-post-name'
17
+ end
18
+
19
+ it "does save without errors" do
20
+ subject.save!
21
+ end
22
+
23
+ context "post meta" do
24
+
25
+ before :each do
26
+ # Posts require to be saved before maniuplating post meta
27
+ subject.save!
28
+ end
29
+
30
+ it "should store a value" do
31
+ subject.post_meta['hello'] = 'there'
32
+ subject.post_meta['hello'].should == 'there'
33
+ end
34
+
35
+ it "should correctly handle an array" do
36
+ the_array = [ 1, 2, 'hello' ]
37
+ subject.post_meta['hello'] = the_array
38
+ subject.post_meta['hello'].should == the_array
39
+ end
40
+
41
+ it "should correctly handle a hash" do
42
+ the_hash = { 'hello' => 'world', 'goodbye' => 'moon' }
43
+ subject.post_meta['hello'] = the_hash
44
+ subject.post_meta['hello'].should == the_hash
45
+ end
46
+
47
+ end
48
+
49
+ context "taxonomies" do
50
+
51
+ before :each do
52
+ # Posts require to be saved before maniuplating taxonomies
53
+ subject.save!
54
+ end
55
+
56
+ it "does start out with no categories" do
57
+ subject.get_the_terms('category').should == []
58
+ end
59
+
60
+ it "does set a category" do
61
+ subject.set_post_terms 'hello', 'category'
62
+ subject.get_the_terms('category').should == ['hello']
63
+ end
64
+
65
+ it "does set multiple categories" do
66
+ subject.set_post_terms ['hello', 'there'], 'category'
67
+ subject.get_the_terms('category').sort.should == ['hello', 'there'].sort
68
+ end
69
+
70
+ it "does clear categories when given an empty array" do
71
+ subject.set_post_terms 'hello', 'category'
72
+
73
+ subject.set_post_terms [], 'category'
74
+ subject.get_the_terms('category').should == []
75
+ end
76
+
77
+ it "does append categories" do
78
+ subject.set_post_terms 'hello', 'category'
79
+ subject.set_post_terms 'there', 'category', true
80
+ subject.get_the_terms('category').sort.should == ['hello', 'there'].sort
81
+ end
82
+
83
+ it "does append multiple categories" do
84
+ subject.set_post_terms 'hello', 'category'
85
+ subject.set_post_terms ['there', 'goodbye'], 'category', true
86
+ subject.get_the_terms('category').sort.should == ['hello', 'there', 'goodbye'].sort
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordPress do
4
+
5
+ subject do
6
+ $wp
7
+ end
8
+
9
+ context "#new_post" do
10
+
11
+ subject do
12
+ $wp.new_post({ :post_title => "Inital Post Title", :post_name => 'inital-post-title' })
13
+ end
14
+
15
+ its :class do
16
+ should be WordPress::Post
17
+ end
18
+
19
+ end
20
+
21
+ context "#query" do
22
+
23
+ it "does query by :post_type" do
24
+ subject.query( :post_type => 'post' ).count.should == 1
25
+ end
26
+
27
+ it "does query by :page_id" do
28
+ subject.query( :page_id => 2 ).count.should == 1
29
+ end
30
+
31
+ it "does query by :pagename" do
32
+ subject.query( :pagename => 'sample-page' ).count.should == 1
33
+ end
34
+
35
+ it "does query by :p" do
36
+ subject.query( :p => 1 ).count.should == 1
37
+ end
38
+
39
+ it "does query by :post__in" do
40
+ subject.query( :post__in => [1] ).count.should == 1
41
+ end
42
+
43
+ it "does query by :post__not_in" do
44
+ subject.query( :post__not_in => [1] ).count.should == 0
45
+ end
46
+
47
+ context "meta queries" do
48
+
49
+ before :each do
50
+ @new_post = $wp.new_post({ :post_title => "Test meta post", :post_name => "test-meta-post", :post_status => 'publish' } )
51
+ @new_post.save!
52
+
53
+ @new_post_2 = $wp.new_post({ :post_title => "Test 2", :post_name => "test-2", :post_status => 'publish' } )
54
+ @new_post_2.save!
55
+ end
56
+
57
+ it "does query by simple meta comparison" do
58
+ @new_post.post_meta['hello'] = 'there'
59
+ subject.query( :meta_query => [ { :key => 'hello', :value => 'there' } ] ).first.should == @new_post
60
+ end
61
+
62
+ it "does query by multiple meta comparison" do
63
+ @new_post.post_meta['hello'] = 'there'
64
+ @new_post.post_meta['goodbye'] = 'moon'
65
+ @new_post_2.post_meta['goodbye'] = 'moon'
66
+
67
+ subject.query( :meta_query => [ { :key => 'hello', :value => 'there' }, { :key => 'goodbye', :value => 'moon' } ] ).first.should == @new_post
68
+ end
69
+
70
+ it "does query by multiple meta comparison with OR" do
71
+ @new_post.post_meta['hello'] = 'there'
72
+ @new_post_2.post_meta['goodbye'] = 'moon'
73
+
74
+ subject.query( :meta_query => [ { :key => 'hello', :value => 'there' }, { :key => 'goodbye', :value => 'moon' } ], :meta_query_relation => 'OR' ).sort.should == [@new_post, @new_post_2]
75
+ end
76
+
77
+ it "does query by LIKE comparison" do
78
+ @new_post.post_meta['hello'] = 'there'
79
+ subject.query( :meta_query => [ { :key => 'hello', :value => 'the%', :compare => 'LIKE' } ] ).first.should == @new_post
80
+ end
81
+
82
+ it "does query by NOT LIKE comparison" do
83
+ @new_post.post_meta['hello'] = 'there'
84
+ subject.query( :meta_query => [ { :key => 'hello', :value => 'the%', :compare => 'NOT LIKE' } ] ).first.should == nil
85
+ end
86
+
87
+ it "does query by BETWEEN using a range" do
88
+ @new_post.post_meta['hello'] = 10
89
+ @new_post_2.post_meta['hello'] = 20
90
+ subject.query( :meta_query => [ { :key => 'hello', :value => (5..15), :compare => 'BETWEEN' } ] ).first.should == @new_post
91
+ end
92
+
93
+ it "does query by BETWEEN using an array" do
94
+ @new_post.post_meta['hello'] = 10
95
+ @new_post_2.post_meta['hello'] = 20
96
+ subject.query( :meta_query => [ { :key => 'hello', :value => [5, 15], :compare => 'BETWEEN' } ] ).first.should == @new_post
97
+ end
98
+
99
+ it "does query by NOT BETWEEN using a range" do
100
+ @new_post.post_meta['hello'] = 10
101
+ @new_post_2.post_meta['hello'] = 20
102
+ subject.query( :meta_query => [ { :key => 'hello', :value => (5..15), :compare => 'NOT BETWEEN' } ] ).first.should == @new_post_2
103
+ end
104
+
105
+ it "does query by NOT BETWEEN using an array" do
106
+ @new_post.post_meta['hello'] = 10
107
+ @new_post_2.post_meta['hello'] = 20
108
+ subject.query( :meta_query => [ { :key => 'hello', :value => [5, 15], :compare => 'NOT BETWEEN' } ] ).first.should == @new_post_2
109
+ end
110
+
111
+ it "does query by IN using a range" do
112
+ @new_post.post_meta['hello'] = 10
113
+ @new_post_2.post_meta['hello'] = 20
114
+ subject.query( :meta_query => [ { :key => 'hello', :value => (5..15), :compare => 'IN' } ] ).first.should == @new_post
115
+ end
116
+
117
+ it "does query by IN using an array" do
118
+ @new_post.post_meta['hello'] = 10
119
+ @new_post_2.post_meta['hello'] = 20
120
+ subject.query( :meta_query => [ { :key => 'hello', :value => [9, 10, 11], :compare => 'IN' } ] ).first.should == @new_post
121
+ end
122
+
123
+ it "does query by NOT IN using a range" do
124
+ @new_post.post_meta['hello'] = 10
125
+ @new_post_2.post_meta['hello'] = 20
126
+ subject.query( :meta_query => [ { :key => 'hello', :value => (5..15), :compare => 'NOT IN' } ] ).first.should == @new_post_2
127
+ end
128
+
129
+ it "does query by NOT IN using an array" do
130
+ @new_post.post_meta['hello'] = 10
131
+ @new_post_2.post_meta['hello'] = 20
132
+ subject.query( :meta_query => [ { :key => 'hello', :value => [9, 10, 11], :compare => 'NOT IN' } ] ).first.should == @new_post_2
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,8 @@
1
+ host: 127.0.0.1
2
+ port: 3306
3
+ username: root
4
+ password:
5
+ encoding: utf8
6
+ database: ruby-wordpress-test
7
+ wordpress_prefix: wp_
8
+ wordpress_wp_content: /tmp/test-contents
@@ -0,0 +1,364 @@
1
+ DROP TABLE IF EXISTS `wp_commentmeta`;
2
+
3
+ CREATE TABLE `wp_commentmeta` (
4
+ `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
5
+ `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
6
+ `meta_key` varchar(255) DEFAULT NULL,
7
+ `meta_value` longtext,
8
+ PRIMARY KEY (`meta_id`),
9
+ KEY `comment_id` (`comment_id`),
10
+ KEY `meta_key` (`meta_key`)
11
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
12
+
13
+ DROP TABLE IF EXISTS `wp_comments`;
14
+
15
+ CREATE TABLE `wp_comments` (
16
+ `comment_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
17
+ `comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT '0',
18
+ `comment_author` tinytext NOT NULL,
19
+ `comment_author_email` varchar(100) NOT NULL DEFAULT '',
20
+ `comment_author_url` varchar(200) NOT NULL DEFAULT '',
21
+ `comment_author_IP` varchar(100) NOT NULL DEFAULT '',
22
+ `comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
23
+ `comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
24
+ `comment_content` text NOT NULL,
25
+ `comment_karma` int(11) NOT NULL DEFAULT '0',
26
+ `comment_approved` varchar(20) NOT NULL DEFAULT '1',
27
+ `comment_agent` varchar(255) NOT NULL DEFAULT '',
28
+ `comment_type` varchar(20) NOT NULL DEFAULT '',
29
+ `comment_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
30
+ `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
31
+ PRIMARY KEY (`comment_ID`),
32
+ KEY `comment_post_ID` (`comment_post_ID`),
33
+ KEY `comment_approved_date_gmt` (`comment_approved`,`comment_date_gmt`),
34
+ KEY `comment_date_gmt` (`comment_date_gmt`),
35
+ KEY `comment_parent` (`comment_parent`)
36
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
37
+
38
+ LOCK TABLES `wp_comments` WRITE;
39
+ /*!40000 ALTER TABLE `wp_comments` DISABLE KEYS */;
40
+
41
+ INSERT INTO `wp_comments` (`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`, `comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`, `comment_content`, `comment_karma`, `comment_approved`, `comment_agent`, `comment_type`, `comment_parent`, `user_id`)
42
+ VALUES
43
+ (1,1,'Mr WordPress','','http://wordpress.org/','','2013-06-08 01:37:36','2013-06-08 01:37:36','Hi, this is a comment.\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.',0,'1','','',0,0);
44
+ UNLOCK TABLES;
45
+
46
+ DROP TABLE IF EXISTS `wp_links`;
47
+
48
+ CREATE TABLE `wp_links` (
49
+ `link_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
50
+ `link_url` varchar(255) NOT NULL DEFAULT '',
51
+ `link_name` varchar(255) NOT NULL DEFAULT '',
52
+ `link_image` varchar(255) NOT NULL DEFAULT '',
53
+ `link_target` varchar(25) NOT NULL DEFAULT '',
54
+ `link_description` varchar(255) NOT NULL DEFAULT '',
55
+ `link_visible` varchar(20) NOT NULL DEFAULT 'Y',
56
+ `link_owner` bigint(20) unsigned NOT NULL DEFAULT '1',
57
+ `link_rating` int(11) NOT NULL DEFAULT '0',
58
+ `link_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
59
+ `link_rel` varchar(255) NOT NULL DEFAULT '',
60
+ `link_notes` mediumtext NOT NULL,
61
+ `link_rss` varchar(255) NOT NULL DEFAULT '',
62
+ PRIMARY KEY (`link_id`),
63
+ KEY `link_visible` (`link_visible`)
64
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
65
+
66
+ DROP TABLE IF EXISTS `wp_options`;
67
+
68
+ CREATE TABLE `wp_options` (
69
+ `option_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
70
+ `option_name` varchar(64) NOT NULL DEFAULT '',
71
+ `option_value` longtext NOT NULL,
72
+ `autoload` varchar(20) NOT NULL DEFAULT 'yes',
73
+ PRIMARY KEY (`option_id`),
74
+ UNIQUE KEY `option_name` (`option_name`)
75
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
76
+
77
+ LOCK TABLES `wp_options` WRITE;
78
+ /*!40000 ALTER TABLE `wp_options` DISABLE KEYS */;
79
+
80
+ INSERT INTO `wp_options` (`option_id`, `option_name`, `option_value`, `autoload`)
81
+ VALUES
82
+ (1,'siteurl','http://snow.local/vanilla-wp','yes'),
83
+ (2,'blogname','WordPress Test','yes'),
84
+ (3,'blogdescription','Just another WordPress site','yes'),
85
+ (4,'users_can_register','0','yes'),
86
+ (5,'admin_email','admin@example.com','yes'),
87
+ (6,'start_of_week','1','yes'),
88
+ (7,'use_balanceTags','0','yes'),
89
+ (8,'use_smilies','1','yes'),
90
+ (9,'require_name_email','1','yes'),
91
+ (10,'comments_notify','1','yes'),
92
+ (11,'posts_per_rss','10','yes'),
93
+ (12,'rss_use_excerpt','0','yes'),
94
+ (13,'mailserver_url','mail.example.com','yes'),
95
+ (14,'mailserver_login','login@example.com','yes'),
96
+ (15,'mailserver_pass','password','yes'),
97
+ (16,'mailserver_port','110','yes'),
98
+ (17,'default_category','1','yes'),
99
+ (18,'default_comment_status','open','yes'),
100
+ (19,'default_ping_status','open','yes'),
101
+ (20,'default_pingback_flag','1','yes'),
102
+ (21,'posts_per_page','10','yes'),
103
+ (22,'date_format','F j, Y','yes'),
104
+ (23,'time_format','g:i a','yes'),
105
+ (24,'links_updated_date_format','F j, Y g:i a','yes'),
106
+ (25,'links_recently_updated_prepend','<em>','yes'),
107
+ (26,'links_recently_updated_append','</em>','yes'),
108
+ (27,'links_recently_updated_time','120','yes'),
109
+ (28,'comment_moderation','0','yes'),
110
+ (29,'moderation_notify','1','yes'),
111
+ (30,'permalink_structure','','yes'),
112
+ (31,'gzipcompression','0','yes'),
113
+ (32,'hack_file','0','yes'),
114
+ (33,'blog_charset','UTF-8','yes'),
115
+ (34,'moderation_keys','','no'),
116
+ (35,'active_plugins','a:0:{}','yes'),
117
+ (36,'home','http://snow.local/vanilla-wp','yes'),
118
+ (37,'category_base','','yes'),
119
+ (38,'ping_sites','http://rpc.pingomatic.com/','yes'),
120
+ (39,'advanced_edit','0','yes'),
121
+ (40,'comment_max_links','2','yes'),
122
+ (41,'gmt_offset','0','yes'),
123
+ (42,'default_email_category','1','yes'),
124
+ (43,'recently_edited','','no'),
125
+ (44,'template','twentytwelve','yes'),
126
+ (45,'stylesheet','twentytwelve','yes'),
127
+ (46,'comment_whitelist','1','yes'),
128
+ (47,'blacklist_keys','','no'),
129
+ (48,'comment_registration','0','yes'),
130
+ (49,'html_type','text/html','yes'),
131
+ (50,'use_trackback','0','yes'),
132
+ (51,'default_role','subscriber','yes'),
133
+ (52,'db_version','22441','yes'),
134
+ (53,'uploads_use_yearmonth_folders','1','yes'),
135
+ (54,'upload_path','','yes'),
136
+ (55,'blog_public','1','yes'),
137
+ (56,'default_link_category','2','yes'),
138
+ (57,'show_on_front','posts','yes'),
139
+ (58,'tag_base','','yes'),
140
+ (59,'show_avatars','1','yes'),
141
+ (60,'avatar_rating','G','yes'),
142
+ (61,'upload_url_path','','yes'),
143
+ (62,'thumbnail_size_w','150','yes'),
144
+ (63,'thumbnail_size_h','150','yes'),
145
+ (64,'thumbnail_crop','1','yes'),
146
+ (65,'medium_size_w','300','yes'),
147
+ (66,'medium_size_h','300','yes'),
148
+ (67,'avatar_default','mystery','yes'),
149
+ (68,'large_size_w','1024','yes'),
150
+ (69,'large_size_h','1024','yes'),
151
+ (70,'image_default_link_type','file','yes'),
152
+ (71,'image_default_size','','yes'),
153
+ (72,'image_default_align','','yes'),
154
+ (73,'close_comments_for_old_posts','0','yes'),
155
+ (74,'close_comments_days_old','14','yes'),
156
+ (75,'thread_comments','1','yes'),
157
+ (76,'thread_comments_depth','5','yes'),
158
+ (77,'page_comments','0','yes'),
159
+ (78,'comments_per_page','50','yes'),
160
+ (79,'default_comments_page','newest','yes'),
161
+ (80,'comment_order','asc','yes'),
162
+ (81,'sticky_posts','a:0:{}','yes'),
163
+ (82,'widget_categories','a:2:{i:2;a:4:{s:5:\"title\";s:0:\"\";s:5:\"count\";i:0;s:12:\"hierarchical\";i:0;s:8:\"dropdown\";i:0;}s:12:\"_multiwidget\";i:1;}','yes'),
164
+ (83,'widget_text','a:0:{}','yes'),
165
+ (84,'widget_rss','a:0:{}','yes'),
166
+ (85,'uninstall_plugins','a:0:{}','no'),
167
+ (86,'timezone_string','','yes'),
168
+ (87,'page_for_posts','0','yes'),
169
+ (88,'page_on_front','0','yes'),
170
+ (89,'default_post_format','0','yes'),
171
+ (90,'link_manager_enabled','0','yes'),
172
+ (91,'initial_db_version','22441','yes'),
173
+ (92,'wp_user_roles','a:5:{s:13:\"administrator\";a:2:{s:4:\"name\";s:13:\"Administrator\";s:12:\"capabilities\";a:62:{s:13:\"switch_themes\";b:1;s:11:\"edit_themes\";b:1;s:16:\"activate_plugins\";b:1;s:12:\"edit_plugins\";b:1;s:10:\"edit_users\";b:1;s:10:\"edit_files\";b:1;s:14:\"manage_options\";b:1;s:17:\"moderate_comments\";b:1;s:17:\"manage_categories\";b:1;s:12:\"manage_links\";b:1;s:12:\"upload_files\";b:1;s:6:\"import\";b:1;s:15:\"unfiltered_html\";b:1;s:10:\"edit_posts\";b:1;s:17:\"edit_others_posts\";b:1;s:20:\"edit_published_posts\";b:1;s:13:\"publish_posts\";b:1;s:10:\"edit_pages\";b:1;s:4:\"read\";b:1;s:8:\"level_10\";b:1;s:7:\"level_9\";b:1;s:7:\"level_8\";b:1;s:7:\"level_7\";b:1;s:7:\"level_6\";b:1;s:7:\"level_5\";b:1;s:7:\"level_4\";b:1;s:7:\"level_3\";b:1;s:7:\"level_2\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:17:\"edit_others_pages\";b:1;s:20:\"edit_published_pages\";b:1;s:13:\"publish_pages\";b:1;s:12:\"delete_pages\";b:1;s:19:\"delete_others_pages\";b:1;s:22:\"delete_published_pages\";b:1;s:12:\"delete_posts\";b:1;s:19:\"delete_others_posts\";b:1;s:22:\"delete_published_posts\";b:1;s:20:\"delete_private_posts\";b:1;s:18:\"edit_private_posts\";b:1;s:18:\"read_private_posts\";b:1;s:20:\"delete_private_pages\";b:1;s:18:\"edit_private_pages\";b:1;s:18:\"read_private_pages\";b:1;s:12:\"delete_users\";b:1;s:12:\"create_users\";b:1;s:17:\"unfiltered_upload\";b:1;s:14:\"edit_dashboard\";b:1;s:14:\"update_plugins\";b:1;s:14:\"delete_plugins\";b:1;s:15:\"install_plugins\";b:1;s:13:\"update_themes\";b:1;s:14:\"install_themes\";b:1;s:11:\"update_core\";b:1;s:10:\"list_users\";b:1;s:12:\"remove_users\";b:1;s:9:\"add_users\";b:1;s:13:\"promote_users\";b:1;s:18:\"edit_theme_options\";b:1;s:13:\"delete_themes\";b:1;s:6:\"export\";b:1;}}s:6:\"editor\";a:2:{s:4:\"name\";s:6:\"Editor\";s:12:\"capabilities\";a:34:{s:17:\"moderate_comments\";b:1;s:17:\"manage_categories\";b:1;s:12:\"manage_links\";b:1;s:12:\"upload_files\";b:1;s:15:\"unfiltered_html\";b:1;s:10:\"edit_posts\";b:1;s:17:\"edit_others_posts\";b:1;s:20:\"edit_published_posts\";b:1;s:13:\"publish_posts\";b:1;s:10:\"edit_pages\";b:1;s:4:\"read\";b:1;s:7:\"level_7\";b:1;s:7:\"level_6\";b:1;s:7:\"level_5\";b:1;s:7:\"level_4\";b:1;s:7:\"level_3\";b:1;s:7:\"level_2\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:17:\"edit_others_pages\";b:1;s:20:\"edit_published_pages\";b:1;s:13:\"publish_pages\";b:1;s:12:\"delete_pages\";b:1;s:19:\"delete_others_pages\";b:1;s:22:\"delete_published_pages\";b:1;s:12:\"delete_posts\";b:1;s:19:\"delete_others_posts\";b:1;s:22:\"delete_published_posts\";b:1;s:20:\"delete_private_posts\";b:1;s:18:\"edit_private_posts\";b:1;s:18:\"read_private_posts\";b:1;s:20:\"delete_private_pages\";b:1;s:18:\"edit_private_pages\";b:1;s:18:\"read_private_pages\";b:1;}}s:6:\"author\";a:2:{s:4:\"name\";s:6:\"Author\";s:12:\"capabilities\";a:10:{s:12:\"upload_files\";b:1;s:10:\"edit_posts\";b:1;s:20:\"edit_published_posts\";b:1;s:13:\"publish_posts\";b:1;s:4:\"read\";b:1;s:7:\"level_2\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:12:\"delete_posts\";b:1;s:22:\"delete_published_posts\";b:1;}}s:11:\"contributor\";a:2:{s:4:\"name\";s:11:\"Contributor\";s:12:\"capabilities\";a:5:{s:10:\"edit_posts\";b:1;s:4:\"read\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:12:\"delete_posts\";b:1;}}s:10:\"subscriber\";a:2:{s:4:\"name\";s:10:\"Subscriber\";s:12:\"capabilities\";a:2:{s:4:\"read\";b:1;s:7:\"level_0\";b:1;}}}','yes'),
174
+ (93,'widget_search','a:2:{i:2;a:1:{s:5:\"title\";s:0:\"\";}s:12:\"_multiwidget\";i:1;}','yes'),
175
+ (94,'widget_recent-posts','a:2:{i:2;a:2:{s:5:\"title\";s:0:\"\";s:6:\"number\";i:5;}s:12:\"_multiwidget\";i:1;}','yes'),
176
+ (95,'widget_recent-comments','a:2:{i:2;a:2:{s:5:\"title\";s:0:\"\";s:6:\"number\";i:5;}s:12:\"_multiwidget\";i:1;}','yes'),
177
+ (96,'widget_archives','a:2:{i:2;a:3:{s:5:\"title\";s:0:\"\";s:5:\"count\";i:0;s:8:\"dropdown\";i:0;}s:12:\"_multiwidget\";i:1;}','yes'),
178
+ (97,'widget_meta','a:2:{i:2;a:1:{s:5:\"title\";s:0:\"\";}s:12:\"_multiwidget\";i:1;}','yes'),
179
+ (98,'sidebars_widgets','a:5:{s:19:\"wp_inactive_widgets\";a:0:{}s:9:\"sidebar-1\";a:6:{i:0;s:8:\"search-2\";i:1;s:14:\"recent-posts-2\";i:2;s:17:\"recent-comments-2\";i:3;s:10:\"archives-2\";i:4;s:12:\"categories-2\";i:5;s:6:\"meta-2\";}s:9:\"sidebar-2\";a:0:{}s:9:\"sidebar-3\";a:0:{}s:13:\"array_version\";i:3;}','yes');
180
+ UNLOCK TABLES;
181
+
182
+ DROP TABLE IF EXISTS `wp_postmeta`;
183
+
184
+ CREATE TABLE `wp_postmeta` (
185
+ `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
186
+ `post_id` bigint(20) unsigned NOT NULL DEFAULT '0',
187
+ `meta_key` varchar(255) DEFAULT NULL,
188
+ `meta_value` longtext,
189
+ PRIMARY KEY (`meta_id`),
190
+ KEY `post_id` (`post_id`),
191
+ KEY `meta_key` (`meta_key`)
192
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
193
+
194
+ LOCK TABLES `wp_postmeta` WRITE;
195
+ /*!40000 ALTER TABLE `wp_postmeta` DISABLE KEYS */;
196
+
197
+ INSERT INTO `wp_postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`)
198
+ VALUES
199
+ (1,2,'_wp_page_template','default');
200
+ UNLOCK TABLES;
201
+
202
+ DROP TABLE IF EXISTS `wp_posts`;
203
+
204
+ CREATE TABLE `wp_posts` (
205
+ `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
206
+ `post_author` bigint(20) unsigned NOT NULL DEFAULT '0',
207
+ `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
208
+ `post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
209
+ `post_content` longtext NOT NULL,
210
+ `post_title` text NOT NULL,
211
+ `post_excerpt` text NOT NULL,
212
+ `post_status` varchar(20) NOT NULL DEFAULT 'publish',
213
+ `comment_status` varchar(20) NOT NULL DEFAULT 'open',
214
+ `ping_status` varchar(20) NOT NULL DEFAULT 'open',
215
+ `post_password` varchar(20) NOT NULL DEFAULT '',
216
+ `post_name` varchar(200) NOT NULL DEFAULT '',
217
+ `to_ping` text NOT NULL,
218
+ `pinged` text NOT NULL,
219
+ `post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
220
+ `post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
221
+ `post_content_filtered` longtext NOT NULL,
222
+ `post_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
223
+ `guid` varchar(255) NOT NULL DEFAULT '',
224
+ `menu_order` int(11) NOT NULL DEFAULT '0',
225
+ `post_type` varchar(20) NOT NULL DEFAULT 'post',
226
+ `post_mime_type` varchar(100) NOT NULL DEFAULT '',
227
+ `comment_count` bigint(20) NOT NULL DEFAULT '0',
228
+ PRIMARY KEY (`ID`),
229
+ KEY `post_name` (`post_name`),
230
+ KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
231
+ KEY `post_parent` (`post_parent`),
232
+ KEY `post_author` (`post_author`)
233
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
234
+
235
+ LOCK TABLES `wp_posts` WRITE;
236
+
237
+ INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`)
238
+ VALUES
239
+ (1,1,'2013-06-08 01:37:36','2013-06-08 01:37:36','Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!','Hello world!','','publish','open','open','','hello-world','','','2013-06-08 01:37:36','2013-06-08 01:37:36','',0,'http://snow.local/vanilla-wp/?p=1',0,'post','',1),
240
+ (2,1,'2013-06-08 01:37:36','2013-06-08 01:37:36','This is an example page. It\'s different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I\'m a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin\' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"http://snow.local/vanilla-wp/wp-admin/\">your dashboard</a> to delete this page and create new pages for your content. Have fun!','Sample Page','','publish','open','open','','sample-page','','','2013-06-08 01:37:36','2013-06-08 01:37:36','',0,'http://snow.local/vanilla-wp/?page_id=2',0,'page','',0);
241
+
242
+ UNLOCK TABLES;
243
+
244
+
245
+ DROP TABLE IF EXISTS `wp_term_relationships`;
246
+
247
+ CREATE TABLE `wp_term_relationships` (
248
+ `object_id` bigint(20) unsigned NOT NULL DEFAULT '0',
249
+ `term_taxonomy_id` bigint(20) unsigned NOT NULL DEFAULT '0',
250
+ `term_order` int(11) NOT NULL DEFAULT '0',
251
+ PRIMARY KEY (`object_id`,`term_taxonomy_id`),
252
+ KEY `term_taxonomy_id` (`term_taxonomy_id`)
253
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
254
+
255
+ LOCK TABLES `wp_term_relationships` WRITE;
256
+
257
+ INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`, `term_order`)
258
+ VALUES
259
+ (1,1,0);
260
+
261
+ UNLOCK TABLES;
262
+
263
+ DROP TABLE IF EXISTS `wp_term_taxonomy`;
264
+
265
+ CREATE TABLE `wp_term_taxonomy` (
266
+ `term_taxonomy_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
267
+ `term_id` bigint(20) unsigned NOT NULL DEFAULT '0',
268
+ `taxonomy` varchar(32) NOT NULL DEFAULT '',
269
+ `description` longtext NOT NULL,
270
+ `parent` bigint(20) unsigned NOT NULL DEFAULT '0',
271
+ `count` bigint(20) NOT NULL DEFAULT '0',
272
+ PRIMARY KEY (`term_taxonomy_id`),
273
+ UNIQUE KEY `term_id_taxonomy` (`term_id`,`taxonomy`),
274
+ KEY `taxonomy` (`taxonomy`)
275
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
276
+
277
+ LOCK TABLES `wp_term_taxonomy` WRITE;
278
+
279
+ INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`)
280
+ VALUES
281
+ (1,1,'category','',0,1);
282
+
283
+ UNLOCK TABLES;
284
+
285
+ DROP TABLE IF EXISTS `wp_terms`;
286
+
287
+ CREATE TABLE `wp_terms` (
288
+ `term_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
289
+ `name` varchar(200) NOT NULL DEFAULT '',
290
+ `slug` varchar(200) NOT NULL DEFAULT '',
291
+ `term_group` bigint(10) NOT NULL DEFAULT '0',
292
+ PRIMARY KEY (`term_id`),
293
+ UNIQUE KEY `slug` (`slug`),
294
+ KEY `name` (`name`)
295
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
296
+
297
+ LOCK TABLES `wp_terms` WRITE;
298
+
299
+ INSERT INTO `wp_terms` (`term_id`, `name`, `slug`, `term_group`)
300
+ VALUES
301
+ (1,'Uncategorized','uncategorized',0);
302
+
303
+ UNLOCK TABLES;
304
+
305
+
306
+ DROP TABLE IF EXISTS `wp_usermeta`;
307
+
308
+ CREATE TABLE `wp_usermeta` (
309
+ `umeta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
310
+ `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
311
+ `meta_key` varchar(255) DEFAULT NULL,
312
+ `meta_value` longtext,
313
+ PRIMARY KEY (`umeta_id`),
314
+ KEY `user_id` (`user_id`),
315
+ KEY `meta_key` (`meta_key`)
316
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
317
+
318
+ LOCK TABLES `wp_usermeta` WRITE;
319
+
320
+ INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
321
+ VALUES
322
+ (1,1,'first_name',''),
323
+ (2,1,'last_name',''),
324
+ (3,1,'nickname','admin'),
325
+ (4,1,'description',''),
326
+ (5,1,'rich_editing','true'),
327
+ (6,1,'comment_shortcuts','false'),
328
+ (7,1,'admin_color','fresh'),
329
+ (8,1,'use_ssl','0'),
330
+ (9,1,'show_admin_bar_front','true'),
331
+ (10,1,'wp_capabilities','a:1:{s:13:\"administrator\";b:1;}'),
332
+ (11,1,'wp_user_level','10'),
333
+ (12,1,'dismissed_wp_pointers','wp330_toolbar,wp330_saving_widgets,wp340_choose_image_from_library,wp340_customize_current_theme_link,wp350_media'),
334
+ (13,1,'show_welcome_panel','1');
335
+
336
+ UNLOCK TABLES;
337
+
338
+
339
+ DROP TABLE IF EXISTS `wp_users`;
340
+
341
+ CREATE TABLE `wp_users` (
342
+ `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
343
+ `user_login` varchar(60) NOT NULL DEFAULT '',
344
+ `user_pass` varchar(64) NOT NULL DEFAULT '',
345
+ `user_nicename` varchar(50) NOT NULL DEFAULT '',
346
+ `user_email` varchar(100) NOT NULL DEFAULT '',
347
+ `user_url` varchar(100) NOT NULL DEFAULT '',
348
+ `user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
349
+ `user_activation_key` varchar(60) NOT NULL DEFAULT '',
350
+ `user_status` int(11) NOT NULL DEFAULT '0',
351
+ `display_name` varchar(250) NOT NULL DEFAULT '',
352
+ PRIMARY KEY (`ID`),
353
+ KEY `user_login_key` (`user_login`),
354
+ KEY `user_nicename` (`user_nicename`)
355
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
356
+
357
+ LOCK TABLES `wp_users` WRITE;
358
+
359
+ INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`)
360
+ VALUES
361
+ (1,'admin','$P$B11mHgyKQHrhtk.LdznSnFAijkNFV80','admin','admin@example.com','','2013-06-08 01:37:36','',0,'admin');
362
+ UNLOCK TABLES;
363
+
364
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-wordpress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keitaroh Kobayashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-05 00:00:00.000000000 Z
11
+ date: 2013-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: A gem to interface with the WordPress database
112
140
  email:
113
141
  - keita@kkob.us
@@ -116,6 +144,7 @@ extensions: []
116
144
  extra_rdoc_files: []
117
145
  files:
118
146
  - .gitignore
147
+ - .travis.yml
119
148
  - Gemfile
120
149
  - LICENSE.txt
121
150
  - README.md
@@ -126,8 +155,15 @@ files:
126
155
  - lib/wordpress/options.rb
127
156
  - lib/wordpress/post.rb
128
157
  - lib/wordpress/post/meta.rb
158
+ - lib/wordpress/schema.rb
129
159
  - lib/wordpress/version.rb
130
160
  - ruby-wordpress.gemspec
161
+ - spec/spec_helper.rb
162
+ - spec/tests/wordpress/options_spec.rb
163
+ - spec/tests/wordpress/post_spec.rb
164
+ - spec/tests/wordpress_spec.rb
165
+ - test_configuration.example.yml
166
+ - wordpress-3.5.1.sql
131
167
  homepage: https://github.com/keichan34/ruby-wordpress
132
168
  licenses:
133
169
  - MIT
@@ -152,4 +188,8 @@ rubygems_version: 2.0.3
152
188
  signing_key:
153
189
  specification_version: 4
154
190
  summary: A gem to interface with the WordPress database
155
- test_files: []
191
+ test_files:
192
+ - spec/spec_helper.rb
193
+ - spec/tests/wordpress/options_spec.rb
194
+ - spec/tests/wordpress/post_spec.rb
195
+ - spec/tests/wordpress_spec.rb