Testing nested attributes with RSpec

So I came across a situation today where I needed to have a particular model accept nested attributes for a related model – much like is demonstrated in the post on integrating advanced forms with Cocoon. Unfortunately, much to my dismay, RSpec doesn’t have any fancy convenience method for testing this. Intarwebz to the rescue!

I found this great little script for doing simple testing for nested attributes, including rejection and acceptance criteria. Just place the code from this gist in a file in your spec/support folder and you’ll magically gain access to a new should matcher – accept_nested_attributes_for.

it { should accept_nested_attributes_for(:association_name) }

Login as User WordPress Plugin

When managing a large WordPress community or when your WordPress setup is a little more than a simple blog, it can be useful to see things from your user’s perspective. I have created a simple Must Use Plugin you can just drop into your WordPress installation that allows a Super Administrator user to login as any user on your website (except for other Super Administrators). This is a highly useful functionality when you need to verify that your interfaces are working not only for your Super Administrator roles, but your other user roles as well.

Check out the plugin on GitHub at: https://github.com/kynatro/loginasuser

Object Oriented jQuery Plugin Boilerplate

I’ve been writing a ton of jQuery plugins lately and decided to create myself a nice little boilerplate with some common structures. This boilerplate will provide the necessary Object Oriented Class based setup for a plugin and its extension of the jQuery.fn Object.

Continue reading “Object Oriented jQuery Plugin Boilerplate”

Easy communication with Rails VirtualBox server

In a recent post I talked about how to setup a Ruby on Rails environment for Mac OS or Ubuntu by itself and in a VirtualBox. In using my VirtualBox Ubuntu server on my Windows laptop, I’ve been annoyed by the constantly changing IP address when networking is configured to Bridge Adapter, so after a little Google sleuthing I was able to find an easy to implement solution: port forwarding. Continue reading “Easy communication with Rails VirtualBox server”

Building a has_many, through model relationship and form with Cocoon

So, I’m working on a personal project to learn Ruby on Rails and the application structure that I desired required a complicated many-to-many relationship with a join model that itself contained data. This was a pretty complex model structure to setup and has numerous pitfall points that took a weekend of searching the Googles and reading a number of StackOverflow entries, GitHub gem documentation and RailsCasts to finally understand and get working the way I desired. Since all the documentation I found only dealt with small pieces of the whole and it took me all weekend to figure it out, I got to thinking there’s no way I’m the only one out there trying to grok this crap. So, now that I got it working, I’m going to share how the heck to do it so you can learn from my guinea pigging.

Continue reading “Building a has_many, through model relationship and form with Cocoon”

Finally a practical use for WordPress’ secret SHORTINIT constant!

Ever write a plugin that needs to utilize AJAX functionality for a rapid response, such as checking if a user exists in the database on key-up, but going through the usual admin-ajax route is too slow? You can write your own AJAX response addressing a PHP file directly with the secret SHORTINIT constant to safely load the WPDB Class and be able to access the WordPress database Object!
Continue reading “Finally a practical use for WordPress’ secret SHORTINIT constant!”

Time to Learn Something New!

I’ve taken it upon myself to start learning a new programming language and leaving my happy little LAMP (or preferably LNMP) comfort zone. I love PHP and how easy it is to get up and running. Its pretty simple and gets the job done quick. PHP unfortunately lacks a lot of the “grace” and modern nuances that a more modern platform such as Ruby on Rails provides.

Now, before the pitchforks start coming out I already know that I’m kind of comparing Apples to Apple Pie. PHP is a language with a ton of community support and Ruby on Rails is a framework. I get it, but there’s a lot to be desired in PHP land. PHP has some good frameworks as well – CakePHP, Zend, CodeIgniter, Yii, etc. – but the sheer variety creates a lot of discontinuity in the community and a lot of the frameworks out there are just Ruby on Rails wannabe’s anyways. More importantly besides any of that, PHP is getting a little boring and I want to learn something new 🙂 So, I’m starting to learn Ruby, Sinatra and eventually Ruby on Rails and share my learning here.

Continue reading “Time to Learn Something New!”

2 New WordPress Plugins – OOP Plugin Boilerplate and MU Utility Plugin

I’ve done a lot of WordPress plugin development lately and thought I’d share some of the great little tools that I’ve used during creation. To start giving back to the community, I’ve decided to make public my OOP WordPress plugin boilerplate and my Utility Functions MU plugin – both valuable tools that I use whenever I’m building a new masterpiece with WordPress.

I’ve done a lot of WordPress plugin development lately and thought I’d share some of the great little tools that I’ve used during creation. To start giving back to the community, I’ve decided to make public my OOP WordPress plugin boilerplate and my Utility Functions MU plugin – both valuable tools that I use whenever I’m building a new masterpiece with WordPress.

Continue reading “2 New WordPress Plugins – OOP Plugin Boilerplate and MU Utility Plugin”

Pure LNMP stack

So, in an effort to save a little cash on hosting I’ve moved my stack on this server to a pure LNMP stack – no Apache, no Varnish. I’ve also introduced a new third-party caching solution called CloudFlare to see if we can take even more traffic off the server. With W3 Total Cache running as well the site is extremely fast, and this only on a 256MB box. Granted, I get about as much traffic as the 395 in the middle of the Mojave, but its fun running at this speed anyways.